【问题标题】:How to change the color of the "check mark" in simple_list_item_checked listView如何更改simple_list_item_checked listView中“复选标记”的颜色
【发布时间】:2015-06-22 05:31:54
【问题描述】:

我有一个扩展ListActivity 的活动。我有一个 SimpleAdapter 正在将字符串数组调整到我的列表视图中。一切都设置得很完美。但是列表视图中的默认复选标记是绿色的。我想改变它的颜色。有人有建议吗?谢谢。

     ListView listview= getListView();
     // listview.setChoiceMode(listview.CHOICE_MODE_NONE);
     // listview.setChoiceMode(listview.CHOICE_MODE_MULTIPLE);
     listview.setChoiceMode(listview.CHOICE_MODE_SINGLE);

        //--    text filtering
     listview.setTextFilterEnabled(true);
     ArrayAdapter<String> adapter = new ArrayAdapter<String>(HomeScreenActivity.this , android.R.layout.simple_list_item_checked,nameStringsArray);
     setListAdapter(adapter);

【问题讨论】:

  • 您需要使用选择器进行自定义。

标签: android android-layout listview android-listview


【解决方案1】:

您可以尝试在您的 XML ListView 中进行设置

android:listSelector="@color/yourcolor"

EDIT: 通过“复选标记”,我认为这是行。由于您使用的是单选模式,我认为该对象是 RadioButton。如果您使用自己的自定义布局,这会更简单,因为您可以访问按钮。但既然不是,你需要定义自己的风格: Is it possible to change the radio button icon in an android radio button group

【讨论】:

  • 这改变了单元格的颜色......这很有帮助。但是您知道如何将复选标记的颜色从默认的绿色更改为另一种颜色吗?谢谢@inmyth
【解决方案2】:

创建自定义行布局是您所需要的。

原因是:复选框图标样式是系统相关属性,您在设备上看到它是绿色的,但在另一个设备上它会是浅蓝色或紫色,...

要自定义复选框图标,请将xml布局文件中复选框的@button属性设置为您想要的新图标。

【讨论】:

    【解决方案3】:

    你可以改变颜色/形式,如何?

    尝试使用btn_Start default system

    android:checkMark="@android:drawable/btn_star"
    

    看看你的代码,玩得开心

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_checked="false" android:state_window_focused="false"
            android:drawable="@drawable/btn_star_big_off" />
        <item android:state_checked="true" android:state_window_focused="false"
            android:drawable="@drawable/btn_star_big_on" />
        <item android:state_checked="true" android:state_window_focused="false"
            android:state_enabled="false" android:drawable="@drawable/btn_star_big_on_disable" />
        <item android:state_checked="false" android:state_window_focused="false"
            android:state_enabled="false" android:drawable="@drawable/btn_star_big_off_disable" />
    
        <item android:state_checked="true" android:state_pressed="true"
            android:drawable="@drawable/btn_star_big_on_pressed" />
        <item android:state_checked="false" android:state_pressed="true"
            android:drawable="@drawable/btn_star_big_off_pressed" />
    
        <item android:state_checked="true" android:state_focused="true"
            android:drawable="@drawable/btn_star_big_on_selected" />
        <item android:state_checked="false" android:state_focused="true"
            android:drawable="@drawable/btn_star_big_off_selected" />
    
        <item android:state_checked="true" android:state_focused="true" android:state_enabled="false"
            android:drawable="@drawable/btn_star_big_on_disable_focused" />
        <item android:state_checked="true" android:state_focused="false" android:state_enabled="false"
            android:drawable="@drawable/btn_star_big_on_disable" />
    
        <item android:state_checked="false" android:state_focused="true" android:state_enabled="false"
            android:drawable="@drawable/btn_star_big_off_disable_focused" />
        <item android:state_checked="false" android:state_focused="false" android:state_enabled="false"
            android:drawable="@drawable/btn_star_big_off_disable" />
    
        <item android:state_checked="false" android:drawable="@drawable/btn_star_big_off" />
        <item android:state_checked="true" android:drawable="@drawable/btn_star_big_on" />
    </selector>
    

    【讨论】:

      【解决方案4】:

      完全没有必要创建自定义复选标记来自定义它。复选标记的空框由主题中的android:textColorSecondary 属性设置。修改选中的颜色,使用colorAccent属性值。

      使用 AppCompat 主题的示例样式:

      <style name="MyListViewActivity" parent="Theme.AppCompat.Light.NoActionBar">
          <item name="android:textColorPrimary">@color/listView_item_text</item>
          <item name="android:textColorSecondary">@color/checkmark_unchecked</item>
          <item name="colorAccent">@color/checkmark_checked</item>
      </style>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-17
        • 2015-02-09
        • 1970-01-01
        • 2021-08-18
        • 1970-01-01
        • 2017-11-22
        相关资源
        最近更新 更多