1. 说明
在我们开发过程中有可能会遇到给我们的根布局设置背景颜色,比如给我们的LinearLayout或者RelativeLayout布局设置背景颜色,其实给布局设置背景颜色有3种方式,分别是:
第一种:
直接在xml布局文件中设置background;
另外2种直接在代码中设置:
// 设置背景颜色
mRelativeLayout.setBackgroundColor(getRescource().getColor(R.color.red)) ;
mRelativeLayout.setBackgroundColor(Color.parseColor(" # FF00FF")) ;
// 设置背景drawable资源
holder.rl_voucher_1.setBackgroundDrawable(context.getDrawable(R.drawable.half_yhj_left)); holder.tv_voucher_buy.setBackgroundDrawable(context.getDrawable(R.drawable.half_yhj_right));