如何以编程方式设置线性布局的背景色?

use*_*968 5 android android-layout

如何以编程方式设置线性布局的背景色?我尝试了以下代码,但无法正常工作:

LinearLayout footer = new LinearLayout(activity);
footer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 8));
footer.setBackgroundColor(Color.parseColor("##ffb5d6e1"));
((LinearLayout)v).addView(footer);
Run Code Online (Sandbox Code Playgroud)

小智 0

基本上这就是您需要设置背景颜色的内容

please follow the following steps
Run Code Online (Sandbox Code Playgroud)

实例化线性布局的视图,如 LinearLayout m=(LinearLayout)findViewByid(R.id.line1); m.setBackground(R.color.back);