In touch mode there is no selected or focused state.
However, you can have a checked state (even without a checkbox) and use that to change properties upon "selection". In your java code where you set up to display your list add this line after you define the listview:
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
Then in your state list XML change this:
android:state_selected="true"
to this:
android:state_activated="true"
So now you should have:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true"
android:drawable="@drawable/selected_item"/>
<item android:drawable="@android:color/transparent" />
</selector>
And finally, set the background for your row view to point to your selector file:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txt_category_row"
android:gravity="center"
android:layout_width="match_parent"
android:textColor="@color/BLACK"
android:layout_height="55dp"
android:padding="10dp"
android:text="@string/hello"
android:layout_marginTop="5dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="@drawable/item_selector" />
You didn't give a name for your state list XML so I just used "item_selector". You should replace that with whatever the name of that file actually is.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…