android - set tab Selected Text Color do not work -


i want change color of tab when it's selected .in matrial design tutorial said set tabselectedtextcolor can that. did n't work me .and force in ontabselected below code:

        public void ontabselected(tablayout.tab tab) {              textview v = (textview) tab.getcustomview().findviewbyid(r.id.text_tab_counter);             v.setvisibility(view.invisible);             textview vv=(textview) tab.getcustomview().findviewbyid(r.id.text_tab);             vv.settextcolor(getresources().getcolor(r.color.notify));             v.settext("");             tab.getcustomview().invalidate();             viewpager.setcurrentitem(tab.getposition());          } 

why didn't work out?

edit becuse have custom tab layout?

    <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="horizontal" android:layout_width="match_parent"     android:layout_height="match_parent"       android:layout_gravity="center"     > <textview      android:textcolor="@color/textcolorprimary"     android:layout_marginright="2dp"     android:id="@+id/text_tab"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     />     <textview         android:text="•"         android:textcolor="@color/notify"         android:textsize="@dimen/badget_size"         android:id="@+id/text_tab_counter"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         />  </linearlayout> 

edit:

viewpageadapter code:

    package ir.whc.news.adapter;  import android.content.context; import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter; import android.view.layoutinflater; import android.view.view; import android.widget.textview;  import java.util.arraylist; import java.util.list;  import ir.whc.news.r;  /**  * created marzieh on 3/31/2016.  */ public class viewpageradapter extends fragmentpageradapter {     private final list<fragment> mfragmentlist = new arraylist<>();     private final list<string> mfragmenttitlelist = new arraylist<>();     private context context;      public viewpageradapter(fragmentmanager manager, context context) {         super(manager);         this.context = context;      }      @override     public fragment getitem(int position) {         return mfragmentlist.get(position);     }      @override     public int getcount() {         return mfragmentlist.size();     }      public void addfrag(fragment fragment, string title) {         mfragmentlist.add(fragment);         mfragmenttitlelist.add(title);     }       @override     public charsequence getpagetitle(int position) {          return mfragmenttitlelist.get(position);     }     public view gettabview(int position,boolean havenew) {           view v = layoutinflater.from(context).inflate(r.layout.custom_tab, null);         textview tv = (textview) v.findviewbyid(r.id.text_tab);         textview tv2= (textview) v.findviewbyid(r.id.text_tab_counter);          tv.settext(getpagetitle(position));         tv.settextcolor(context.getresources().getcolor(r.color.textcolorprimary));         //tv2.settext(string.valueof(count));         //tv2.setvisibility(havenew ? view.visible : view.invisible);         tv2.settext(havenew?context.getstring(r.string.newbadgersign):"");         tv2.settextcolor(context.getresources().getcolor(r.color.notify));          return v;     }  } 

add in material tablayout:

 app:tabtextcolor="@color/normal_color"  app:tabselectedtextcolor="@color/selected_color"    <android.support.design.widget.tablayout             android:id="@+id/tabs"             android:layout_width="match_parent"             android:layout_height="wrap_content"             app:tabgravity="fill"             app:tabtextappearance="@style/customtabtext"             app:tabtextcolor="@color/text_color"             app:tabselectedtextcolor="@color/text_color"             app:tabmode="fixed" /> 

and custom tablayout add in getview() method:

tabtitleview.settextcolor(getresources().getcolorstatelist(r.drawable.selector_textview));

add in drawable selector_textview.xml:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" >     <item android:state_selected="true" android:color="@color/selected_color" />     <item android:state_focused="true" android:color="@color/selected_color" />     <item android:state_pressed="true" android:color="@color/selected_color" />     <item android:color="@color/normal_color" />  </selector> 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -