Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TabLayout color of selected tab underline

How can I change the color of the underline of the selected tab on the new TabLayout? The PagerTabStrip has a method setTabIndicatorColor(int color), TabLayout doesn't seem to have such a method.

enter image description here

like image 958
fweigl Avatar asked Jun 09 '15 07:06

fweigl


People also ask

How do you change the text color on a selected tab?

Right-click the worksheet tab whose color you want to change. Choose Tab Color, and then select the color you want. The color of the tab changes, but not the color of the font.

What is Tab layout?

In Android TabLayout is a new element introduced in Design Support library. It provides horizontal layout to display tabs on the screen. We can display more screens in a single screen using tabs. We can quickly swipe between the tabs.

Can I use tabLayout without ViewPager?

These methods have a features: always attaching the "tab widget" with a ViewPager , and in order to make this requirement, we must disable swipe feature of the ViewPager . Now, with Material design, we now use TabLayout widget, which can "stand alone" to build a tab bar and do not need a ViewPager anymore.


2 Answers

Use app:tabIndicatorColor.

Example:

<android.support.design.widget.TabLayout     android:id="@+id/tabs"     android:layout_width="match_parent"     android:layout_height="wrap_content"     app:tabIndicatorColor="@android:color/white" /> 

Make sure you have this namespace: xmlns:app="http://schemas.android.com/apk/res-auto"

Documentation: https://developer.android.com/reference/android/support/design/widget/TabLayout.html#attr_android.support.design:tabIndicatorColor.

like image 167
Jared Burrows Avatar answered Sep 21 '22 15:09

Jared Burrows


Try to download below file from this location :

https://github.com/google/iosched/tree/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget

SlidingTabLayout.java SlidingTabStrip.java 

Try to set tab indicator color this way :

slidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {      @Override      public int getIndicatorColor(int position) {         return getResources().getColor(R.color.color_name);      } }); 
like image 26
Haresh Chhelana Avatar answered Sep 25 '22 15:09

Haresh Chhelana