版权声明:本文为博主原创文章,未经博主允许不得转载. 前言 在Android开发中,经常需要设置控件的背景颜色或者图片的src颜色. 效果图 代码分析 根据使用的方法不同,划分为 setBackgroundColor方法[一般用于RelativeLayout.TextView等控件] 使用colors.xml文件中的颜色 使用颜色的int类型值 使用颜色的16进制类型值 setImageDrawable方法[一般用于ImageView控件] 使用colors.xml文件中的颜色 使用颜色的int…
android中,要使控件获得焦点,需要先setFocus,再requestFocus. 以Button为例:                 btn.setFocusable(true);                 btn.setFocusableInTouchMode(true);                 btn.requestFocus();                 btn.requestFocusFromTouch(); 转自:链接…
android中,要使控件获得焦点,需要先setFocus,再requestFocus. 以Button为例:                btn.setFocusable(true);                btn.setFocusableInTouchMode(true);                btn.requestFocus();                btn.requestFocusFromTouch(); //获得失去焦点的监听器 btn.setOnFocu…
在MFC中设置控件的背景色.字体.字体颜色.标题等属性主要是利用OnCtlColor函数来实现. 如: HBRUSH CAlarm::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)  { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here //设置静态控件的背景色和文本颜色 if (pWnd->G…
1.给程序设置大背景色,在OnPaint()函数中添加如下代码: CRect rect; CPaintDC dc(this); GetClientRect(rect); dc.FillSolidRect(rect, RGB(, , )); dc.FillPath(); 2.给个控件修改背景颜色,先在类向导中添加WM_CTLCOLOR消息,然后就会自动添加OnCtColor()函数: HBRUSH CMFCApplication1Dlg::OnCtlColor(CDC* pDC, CWnd* pW…
在Android中经常出现多线程中设置控件的值报错的情况,今天教大家封装一个简单的类避免这样的问题,同样也调用实现也非常的方便. 自定义类: /** * Created by wade on 2016/5/3. * <p/> * 自定义多线程中设置控件的值 */ public abstract class RunThread { private Handler handler = new Handler() { @Override public void handleMessage(Messa…
android中在java代码中设置Button按钮的背景颜色 1.设置背景图片,图片来源于drawable: flightInfoPanel.setBackgroundDrawable(getResources().getDrawable(R.drawable.search_label_click)); 2.转换字符串为int(颜色): listItemView.deleteFilghtBg.setBackgroundColor(Color.parseColor("#F5F5DC")…
根据业务的需要,要在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom属性. 我们知道在xml中设置的方法为:android:drawableLeft="@drawable/xxxxx"; 但是在代码中并没有相关的setDrawableLeft等方法.怎么办呢?别担心,api为我们提供了一个setCompoundDrawables(left,top,right,bottom);方法,供开发人员设置相应的边界图片.…
1 TextView文本框 1.1 TextView类的结构 TextView 是用于显示字符串的组件,对于用户来说就是屏幕中一块用于显示文本的区域.TextView类的层次关系如下: java.lang.Object   ↳ android.view.View   ↳ android.widget.TextView 直接子类: Button, CheckedTextView, Chronometer, DigitalClock, EditText 间接子类: AutoCompleteTextV…
本文採用一个Demo来展示Android中ExpandableListView控件的使用,如怎样在组/子ListView中绑定数据源.直接上代码例如以下: 程序结构图: layout文件夹下的 main.xml 文件源代码例如以下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/a…