具有替代颜色和焦点颜色的Android ListView

标签 android listview colors alternate

我需要在 ListView 行中设置替代颜色,但是当我这样做时,它会删除/禁用聚焦默认黄色背景

我试过 backgroundColor rowView.setBackgroundColor(一些颜色);

还有 backgrounddrwable。

rowView.setBackgroundColor(R.drawable.view_odd_row_bg);
<?xml version="1.0" encoding="utf-8"?>
<selector
   xmlns:android="http://schemas.android.com/apk/res/android">
   <item
      android:state_window_focused="false"
      android:drawable="@color/odd" />

   <!--
      Even though these two point to the same resource, have two states
      so the drawable will invalidate itself when coming out of pressed
      state.
   -->
   <item
      android:state_focused="true"
      android:state_enabled="false"
      android:state_pressed="true"
      android:drawable="@color/highlight" />
   <item
      android:state_focused="true"
      android:state_enabled="false"
      android:drawable="@color/highlight" />

   <item
      android:state_focused="true"
      android:state_pressed="true"
      android:drawable="@color/highlight" />
   <item
      android:state_focused="false"
      android:state_pressed="true"
      android:drawable="@color/highlight" />

   <item
      android:state_focused="true"
      android:drawable="@color/highlight" />

</selector>

但它不会工作。

有什么方法可以同时设置背景颜色和焦点颜色吗?

最佳答案

我发现本教程对我很有帮助。

http://ykyuen.wordpress.com/2010/03/15/android-%E2%80%93-applying-alternate-row-color-in-listview-with-simpleadapter/

我能够使 ListView 项目具有交替的颜色,并且焦点项目保持默认突出显示的颜色。

关于具有替代颜色和焦点颜色的Android ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3061288/

相关文章:

javascript - 色彩平衡公式添加过多白色

ios - 通过 Storyboard命名颜色

java - 使用 ResideMenu lib 时删除菜单项

android - 由 : org. koin.core.error.InstanceCreationException : Could not create instance for [type:Factory, primary_type 引起

java - Android 联系人 - 检索 Android 联系人,如何将它们放入简单的 ListView 中?

C# WPF OnPropertyChanged 在 foreach 循环中

Android:带复选框的ListView

javascript - 颜色 (h,s,b) 从 360 到 0、从 0 到 (-360) 以及从 (-360) 到 (-720) 等等

android - 将 5mb 数据文件复制到数据库后,如何清除 android 中的堆内存?

android - Google API 对来自 GoogleAuthUtil.getToken 的一次性授权代码的授予无效