2015-04-16 43 views
3

我有一項活動延伸到ListActivity。我有一個SimpleAdapter,它將一個字符串數組調整到我的列表視圖中。一切都設置完美。但是,listview中的默認選中標記是綠色的。我想改變它的顏色。有人有建議嗎?謝謝。如何更改simple_list_item_checked中的「複選標記」的顏色listView

 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); 
+0

你需要使它自定義使用選擇。 – Piyush

回答

0

您可以嘗試在你的XML的ListView

android:listSelector="@color/yourcolor" 

EDIT:設置此所謂 「對號」 我認爲這是該行。既然你使用單選模式,我認爲對象是RadioButton。如果你使用你自己的自定義佈局,你將可以訪問按鈕,這會更簡單。但既然不是你需要定義自己的風格: Is it possible to change the radio button icon in an android radio button group

+0

這改變了細胞的顏色......這是有幫助的。但是您知道如何將複選標記的顏色從默認綠色更改爲另一種顏色。謝謝@inmyth –

0

創建一個自定義的行佈局就是你需要的。

的原因是:複選框圖標風格與系統相關的屬性,你也看到了綠色的設備上,但另一臺設備上這將是淡藍色或紫色,...

要自定義複選框圖標,設置@您的xml佈局文件中的複選框的按鈕屬性添加到您想要的新圖標。

0

您可以更改顏色/形式,如何?

嘗試使用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> 
0

我們絕對沒有必要爲了進行定製,以創建一個自定義複選標記。複選標記的空框架由您主題中的android:textColorSecondary屬性設置。要修改選中的顏色,請使用colorAccent屬性值。使用程序兼容性主題

樣本樣式:

<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> 
相關問題