3种方式设置TextView控件的背景颜色
1.textview.setBackgroundResource(R.color.background);
2.textview.setBackgroundColor(Color.RED);
3.textview.setBackgroundDrawable(getResources().getDrawable(R.drawable.search_label_click));
动态设置drawableLeft 图片
// 动态设置
Drawable drawable= getResources().getDrawable(R.drawable.drawable);
// 这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
myTextview.setCompoundDrawables(drawable,null,null,null);
//===== 动态添加控件
width = wm.getDefaultDisplay().getWidth() / 5;
height = wm.getDefaultDisplay().getHeight();
ImageView imageView = new ImageView(context);
LinearLayout layout = new LinearLayout(context);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.width = width;
params.height = width;
layout.addView(imageView, params);