Search...

Monday, February 27, 2012

How to change colour of activated list item background on Honeycomb android?


(1) background_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"
        >
 
 
    <item android:state_activated="true" android:drawable="@drawable/hilight_blu" />

    <item android:state_activated="true"  android:drawable="@drawable/hilight_blu"/>

    <item android:state_focused="true" android:state_enabled="false"
        android:state_pressed="true"
        android:drawable="@drawable/hilight_blu" />
     
     <item android:state_focused="true" android:state_selected="true" android:state_pressed="false"      android:drawable="@drawable/hilight_blu"/>
    <item android:state_focused="true" android:state_enabled="false"
        android:drawable="@drawable/hilight_blu" />

    <item android:state_focused="true" android:state_pressed="true"
        android:drawable="@drawable/hilight_blu" />
     
    <item android:state_focused="false" android:state_pressed="true"
        android:drawable="@drawable/hilight_blu" />
     
         <item android:state_focused="false" android:state_selected="true"
        android:drawable="@drawable/hilight_blu" />

    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false"     android:drawable="@drawable/hilight_blu"/>
 
     <item android:drawable="@color/transparent" />
 </selector>

(2) list_item.xml




  <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="11dp" android:background="@drawable/background_selector"
    android:paddingBottom="11dp"
    android:paddingLeft="23dp" android:textAppearance="@style/sans17white">
</TextView>


(3)Setting the adapter values.

ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
getActivity(), R.layout.list_item,getCustomCategory());
categoryList.setAdapter(adapter);
categoryList.setOnItemClickListener(categoryListener);

(4)Selecting item



AdapterView.OnItemClickListener categoryListener = new AdapterView.OnItemClickListener() {

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {


selectListItem(arg2);


}

};









No comments:

Post a Comment