android - Setting the text color based on state of a Custom Tab View -


i able implement custom tab view assistance of question on stackoverflow. have custom tab view follows.

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/tablayout"  android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:padding="5dip">  <imageview android:id="@+id/tabimageview" android:layout_width="wrap_content"  android:layout_height="wrap_content"/>  <textview android:id="@+id/tabtextview" android:text="text" android:paddingtop="5dip"        android:layout_width="wrap_content" android:layout_height="wrap_content" />  </linearlayout> 

i inflate follows

mainactivity.addtab(this, this.mtabhost,     this.mtabhost.newtabspec("tab1").setindicator(preparetabview("smoker",     r.drawable.ic_smoker)), ( tabinfo = new tabinfo("tab1", mainfragment.class, args))); 

function looks follows

private view preparetabview(string text, int resid) {     view view = layoutinflater.from(this).inflate(r.layout.tab, null);     imageview iv = (imageview) view.findviewbyid(r.id.tabimageview);     textview tv = (textview) view.findviewbyid(r.id.tabtextview);     iv.setimageresource(resid);     tv.settext(text);     return view; } 

i have style defined drawable resource follows

<selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/ic_smoker_green" /> <item android:drawable="@drawable/ic_smoker_red" /> </selector>

my question how text color change based on state of tab?

set in main xml textview

android:textcolor="@drawable/text_col" 

and in drawable create file text_col.xml, hope do

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">  <item android:state_focused="true" android:state_pressed="false" android:color="#ff7bcffc" /> <item android:state_focused="true" android:state_pressed="true" android:color="#ff7bcffc" /> <item android:state_focused="false" android:state_pressed="true" android:color="#ff7bcffc" />  <item android:state_selected="true" android:color="@drawable/box_col" ></item> <item android:color="#ffffffff" /> 


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -