Android ListView text color change
I'm working with list view, and try to achive desire look. Long stroy short - I want to change list item text View color when item is pressed. Default text color for textView is White, and when I press item in listView text Color automaticly change to Black. It is default settings and it works pretty well. But when I set color in text View, for example in Red then nothing happen when item in list View is pressed. I try to set color selector for Text View but it doesn't work(even if I set duplicateParentState=true)
I Just want some defa开发者_如何转开发ult text color and diffrent text color when user press item.
Thx for help.
put this file in res/color folder color_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false"
android:color="@color/skyblue" />
<item android:state_focused="true" android:state_pressed="true"
android:color="@color/white" />
<item android:state_focused="false" android:state_pressed="true"
android:color="@color/white" />
<item android:color="@color/skyblue" />
</selector>
now set this selector in your Textview's textcolor property prepare a color.xml in "values" folder
color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#ffffffff</color>
<color name="blue">#39abdf</color>
</resources>
You have to override the baseadapter. It is not difficult. This will allow you to target each element in each row and even allow for clicking of buttons and such on each row.
Here is one link. I know there are more. Ill post them if I come across them again.
Android: ListView elements with multiple clickable buttons
Android : BaseAdapter how to?
You can override the onItemClick() event and use the View that is given to you in the method. Using that, you can call View.findViewById(R.id.textview) for each of the textviews to change their font and font color.
精彩评论