Android动态界面backgroundcolor

时间:2012-08-22 11:54:41

标签: android dynamic interface background-color

我正在创建一个基于sharedpreferences字符串的动态接口。

继承我的代码

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    CreateInterface();

}//End-OnCreate 

public void CreateInterface()
{
    ScrollView sv = new ScrollView(this);
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);

    TableLayout tl = new TableLayout(this);
    TableRow[] tr = null;


    // Here is a loop that creates tablerow, create button in that, and add tablerow to tablelayout tl. This part is irrelevant couse it works perfectly.

    ll.addView(tl);

    sv.addView(ll);
    setContentView(sv);
}

现在,我想改变屏幕的背景颜色。我该怎么做呢?

2 个答案:

答案 0 :(得分:1)

使用以下方法设置ScrollView或LinearLayout背景颜色。

sv.setBackgroundColor(); or ll.setBackgroundColor();

使用getResources().getColor(R.color.yourColorID);

获取颜色字符串

答案 1 :(得分:1)

ll.setBackgroundColor()应该完成这项工作。