2016-11-03 3 views
0

Ich versuche, die ausgewählten Registerkarte zu bekommen NUR in verschiedenen Farben zu sein, bitte den folgenden Code,TabLayout Wechsel tabText Farbe

viewPager = (ViewPager) findViewById (R.id.pager) zu sehen;

tabLayout = (TabLayout) findViewById(R.id.tab_layout); 
    tabLayout.addTab(tabLayout.newTab().setText("Chats ")); 
    tabLayout.addTab(tabLayout.newTab().setText("Services")); 
    tabLayout.addTab(tabLayout.newTab().setText("Favourite")); 
    tabLayout.setTabTextColors(-1,-256); 
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); 

    viewPager.setAdapter(mAdapter); 
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); 


    tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { 
     @Override 
     public void onTabSelected(TabLayout.Tab tab) { 
       viewPager.setCurrentItem(tab.getPosition()); 
     } 

     @Override 
     public void onTabUnselected(TabLayout.Tab tab) { 

     } 

     @Override 
     public void onTabReselected(TabLayout.Tab tab) { 

     } 
    }); 

mein xml:

<android.support.design.widget.TabLayout 
    android:layout_height="?attr/actionBarSize" 
    android:layout_width="match_parent" 
    android:id="@+id/tab_layout" 
    style="@style/MyCustomTabLayout" 
    /> 

und mein Stil:

<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout"> 
    <item name="tabTextAppearance">@style/MyCustomTabText</item> 
    <item name="tabSelectedTextColor">@color/colorAccent</item> 
</style> 

<style name="MyCustomTabText" parent="TextAppearance.AppCompat.Button"> 
    <item name="android:textSize">14sp</item> 
    <item name="android:textColor">@color/theme_blue</item> 
</style> 

Bitte helfen Sie mir, um zu sehen, was die Bearbeitung benötigt, so dass nur eine Registerkarte auf einmal eine andere Farbe bekommt !

Vielen Dank im Voraus

Antwort

1

Sie können diese mit App tun: tabTextColor und App: tabSelectedTextColor

So:

<android.support.design.widget.TabLayout 
    android:layout_height="?attr/actionBarSize" 
    android:layout_width="match_parent" 
    android:id="@+id/tab_layout" 
    app:tabTextColor="@color/theme_blue" 
    app:tabSelectedTextColor="@color/colorAccent" 
    style="@style/MyCustomTabLayout"/>