设置View控件的背景色
1、setBackground(Drawable background)
参数为Drawable对象,用于设置背景图片
Drawable对象的获取:
注:当不在Activity中,可用Context对象调用getResources()
方法、getDrawable()
方法以及用Context对象代替this
2、setBackgroundColor(int color)
设置View的背景颜色
设置参数的方式:应该是解析的颜色而不是资源的id
int color = getContext().getResources().getColor(R.color.xxx)
3、setBackgroundResource(int resid)
设置View的背景图片(drawable中的资源文件)
设置参数方式:
int resid = R.drawable.xxx
4、setBackgroundDrawable(Drawable background)
过时方法,被setBackground取代