I've done a Gallery view composed by just textviews as numbers. By default if I don't set any colors the item in the centre is black. I want to change it.
Using a selector it doesn't work, any ideas?
UPDATE: if I try to use a selector also the default behavior gone and I can see only grey textview
So, this is the getVIew of my TextAdapter that extends BaseAdapter
public View getView(int position, View convertView, ViewGroup parent) {
TextView t = new TextView(mContext);
int val = position + 1;
t.setText("" + val);
t.setTextSize(30f);
t.setTextColor(R.drawable.numericgallery_selector);
return t;
}
and this is my selector.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_开发者_开发问答selected="true" android:color="#FDF132"></item>
<item android:state_selected="false" android:color="#CADDCD"></item>
<item android:color="#FFFFFF"></item>
</selector>
but it doen't work.... :(
I found my old post with no solution. So I tell you how I worked it out.
t.setTextColor(mContext.getResources().getColorStateList(R.drawable.numericgallery_selector));
Inflate the TextView to use inside the gallery. Then it does not require to change any thing dynamically.
<?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:textSize="12sp"
**android:textColor="@drawable/tracker_selected_color"**
android:id="@+id/textview_tracker_item"
android:textStyle="bold"
/>
and then try tracker_selected_color.xml
<item android:state_selected="true" android:color="#FDF132"></item>
<item android:state_selected="false" android:color="#CADDCD"></item>
<item android:color="#FFFFFF"></item>
精彩评论