I recently started using android actionbars and contextual action bars (CAB).
I have just one activity which is a ListActivity. Basically I use the following code snippe
Only trying to support ICS devices and up but this new layout does what you are trying to achieve, in keeping the selected line highlighted.
adapter = new SimpleCursorAdapter(getActivity(),
android.R.layout.simple_list_item_activated_1,
null,
from,
to,
0);
Just create a a drawable called custom_background on the way:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/highlight" android:state_activated="true"/>
<item android:drawable="@color/normal"/>
</selector>
and set as background on your parent layout:
android:background="@drawable/custom_background"
For anyone still meet this issue, please check your android:minSdkVersion. If it's too low, selector background color may not work.
I've only ever tested this in CHOICE_MODE_SINGLE, but in that situation it works by doing the following.
When you select a list item, in code, call "setItemChecked(position, checked)" method (on the ListView instance) for that item in the list.
Add this to the XML for individual ListView items:
android:background="?android:attr/activatedBackgroundIndicator"