-1

How do I change the text color and style of the the tab layout?

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:background="#2096f3"
    android:elevation="6dp"
    android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
Panda
  • 152
  • 2
  • 10

1 Answers1

0

You can extend TabLayout to provide your own view for tabs.

public class CustomTabLayout extends TabLayout {

public CustomTabLayout (final Context context) {
    super(context);
}

public CustomTabLayout (final Context context, final AttributeSet attrs) {
    super(context, attrs);
}

public CustomTabLayout (final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

public void setTabsFromPagerAdapter(@NonNull final PagerAdapter adapter) {
    removeAllTabs();
    int i = 0;

    final LayoutInflater inflater = LayoutInflater.from(getContext());
    for(int count = adapter.getCount(); i < count; ++i) {
        final TextView tab = (TextView) inflater.inflate(R.layout.custom_tab, this, false);
        tab.setText(local.getPageTitle(i));            
        this.addTab(this.newTab().setCustomView(tab));
    }
}

}

Bracadabra
  • 3,609
  • 3
  • 26
  • 46