开发者

How to set ListView background?

I want to set white as a background color in my ListView.

This is my code:

rect.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        ArrayAdapter adapter =
            new ArrayAdapter(Drejeskive.开发者_JAVA百科this,
                             android.R.layout.simple_spinner_item,
                             digits);
        ListView vl = new ListView(getApplicationContext());
        vl.setBackgroundColor(R.drawable.list_bg);
        vl.invalidate();
        layout.addView(vl);
        vl.setAdapter(adapter);
    }
});

rect - it is my button

list_bg is below

<item android:drawable="@color/white" />

Why doesn't it work?


You should use setBackgroundResource(R.color.myRow_red) instead of that and setBackgroundColor(). In your example background color is assigned with the ID instead of the actual color described in the resources

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜