ListView item的背景色 listviewitem 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在adapter中的getview里面if (position % 2 == 0) {//奇偶行背景色 contentView.setBackgroundColor(contentView.getResources().getColor(R.color.palegreen)); }else { contentView.setBackgroundColor(contentView.getResources().getColor(R.color.lightgreen)); } 你首先得为你的contentView设置Background,然后设置BackgroundColor才能看到效果 我是直接设置<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="80dp" android:paddingBottom="5dp" android:paddingLeft="5dp" android:paddingTop="5dp" android:id="@+id/rl_main" >if (arg0 % 2 == 0) { viewholder.rl_main.setBackgroundColor(R.color.Black); }else { viewholder.rl_main.setBackgroundColor(R.color.White); } 可以在adapter的的view中代码设置背景色通过position来区别奇偶~ 这个之前遇到过,你直接在contentView里面设置是不行的。 是需要把焦点获取到item上面。然后再给contentView设置背景。通过position操作contentView就可以了。可以试试,不一定好使。 android網頁存取 android tabhost如何设置标签的间距 如何在android程序中读txt文件中的内容 android游戏中载入音乐的问题 求助高难度问题:Dialog大小问题 遇到一个很奇怪的问题,请大家帮忙看一下 SSH搭建的android服务器!让被人访问!!!!1 自定义的view如何跳转activity Android如何解析webservice返回的数据 按钮监听器,不知道怎么出现尖括号了 android4.4.4源码编译报错 请教懂得切图的大神回答我个问题
if (position % 2 == 0) {//奇偶行背景色
contentView.setBackgroundColor(contentView.getResources().getColor(R.color.palegreen));
}else {
contentView.setBackgroundColor(contentView.getResources().getColor(R.color.lightgreen));
}
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="80dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:id="@+id/rl_main"
>
if (arg0 % 2 == 0) {
viewholder.rl_main.setBackgroundColor(R.color.Black);
}else
{
viewholder.rl_main.setBackgroundColor(R.color.White);
}
是需要把焦点获取到item上面。然后再给contentView设置背景。通过position操作contentView就可以了。可以试试,不一定好使。