Android的ListView的背景颜色总是显示灰色 [英] Android ListView background colors always showing grey

查看:205
本文介绍了Android的ListView的背景颜色总是显示灰色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ListView 的我是从一个自定义的ListAdapter 。里面的适配器(在<一个href="http://developer.android.com/reference/android/widget/Adapter.html#getView%28int,%20android.view.View,%20android.view.ViewGroup%29">getView(int,查看,ViewGroup中)法)我设置视图的背景颜色使用<一个href="http://developer.android.com/reference/android/view/View.html#setBackgroundColor%28int%29">setBackgroundColor(int).问题是,不管是什么颜色我设置的背景,它永远是一个暗灰色。它也可能是值得指出的是,我使用的是光的主题。

I have a ListView that I'm populating from a custom ListAdapter. Inside the Adapter (in the getView(int, View, ViewGroup) method) I'm setting the background color of the View using setBackgroundColor(int). The problem is that no matter what color I set the background to it always comes out a dark grey. It might also be worth noting that I'm using the Light theme.

相关(简体)的code位:

AndroidManifest.xml中:

AndroidManifest.xml:

<activity 
    android:name=".MyActivity"
    android:theme="@android:style/Theme.Light" />

MyAdapter.java:

MyAdapter.java:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(mContext);
    View av = inflater.inflate(R.layout.my_row, parent, false);
    av.setBackgroundColor(R.color.myRow_red);
    mName = (TextView) av.findViewById(R.id.myRow_name);
    mName.setText("This is a name");
    return av;
}

任何意见/建议?

Any ideas/suggestions?

推荐答案

您应该使用: setBackgroundResource(R.color.myRow_red) 而不是 setBackgroundColor的()在你的榜样背景颜色分配,而不是在资源描述的实际颜色与ID

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

这篇关于Android的ListView的背景颜色总是显示灰色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆