开发者

How to set ListView background?

开发者 https://www.devze.com 2023-03-14 10:28 出处:网络
I want to set white as a background color in my ListView. This is my code: rect.setOnClickListener(new View.OnClickListener() {

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

精彩评论

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

关注公众号