I am totaly new in Android development.
I try to change the FontColor and the Background of ListViewItem if it`s selected or pressed. Changing the Background is absolutely no Problem by using following selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/background_pressed"></item>
<item android:state_focused="true"
android:drawable="@drawable/background_pressed"></item>
<item android:state_selected="true"
android:drawable="@drawable/background_pressed"></item>
<item android:drawable="@android:color/transparent"></item>
</selector>
But how can I change the Background and the FontColor?
Try this
Changing the TextView's font color is done in the same way as the listitem's backgroundcolor: create a StateListDrawable and set the
TextView
'sandroid:textColor
to your custom drawable.For an example, see Change ListViews text color on click. Combine this with what you already have for the listitem's background.
If you want the colors to fade into eachother, set (e.g.)
android:exitFadeDuration="@android:integer/config_mediumAnimTime"
in the<selector>
-tag.