4

I have an activity that extends ListActivity. I have a SimpleAdapter that is adapting an array of strings into my list view. Everything is set up perfectly. But the default check mark in the listview is green. I would like to change its color. Does anyone have any advice? Thank you.

     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);
Piyush
  • 18,895
  • 5
  • 32
  • 63
Wildblue09
  • 337
  • 1
  • 3
  • 13

4 Answers4

0

You can try setting this in your XML ListView

android:listSelector="@color/yourcolor"

EDIT: By "checkmark" I thought it was the row. Since you are using single choice mode I think the object is RadioButton. This would be simpler if you use your own custom layout for you would have access to the button. But since it's not you would need to define your own style: Is it possible to change the radio button icon in an android radio button group

Community
  • 1
  • 1
inmyth
  • 8,880
  • 4
  • 47
  • 52
  • That changed the color of the cell... that was helpfull. but do you know how to change the color of the checkmark from the default green to another color. thanks @inmyth – Wildblue09 Apr 16 '15 at 02:58
0

Create a custom row layout is what you need.

The reason is: checkbox icon style is system-dependent attribute, you saw it green on your device but on another device it will be light blue or purple, ...

To customize checkbox icon, set @button attribute of checkbox in your xml layout file to your new icon you want.

quocnhat7
  • 213
  • 1
  • 10
0

You can change color / form , How ?

Try use btn_Start default system :

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

And see your code, Have fun

<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>
0

There is absolutely no need to create a custom checkmark in order to customize it. The empty frame of the checkmark is set by android:textColorSecondary attribute in your theme. To modify the checked color, colorAccent attribute value is used.

Sample style using an AppCompat theme:

<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>
Aleks N.
  • 6,051
  • 3
  • 42
  • 42