How to change selected Tab Text color using TabLayout from code in Android?

后端 未结 8 904
悲哀的现实
悲哀的现实 2020-12-13 01:58

\"enter

I\'m using android.support.widget.TabLayout

相关标签:
8条回答
  • 2020-12-13 02:30

    It's so simple using XML. Just add the following 2 attributes in your tab layout.

    app:tabSelectedTextColor="@color/color_primary_text"
    app:tabTextColor="@color/color_secondary_text"
    

    So, your code would look something like this.

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:layout_gravity="bottom"
        android:background="@color/button_background"
        android:fillViewport="true"
        app:tabBackground="@drawable/fixed_bottom_button"
        app:tabIndicatorColor="@color/color_primary_text"
        app:tabMode="fixed"
        app:tabSelectedTextColor="@color/color_primary_text"
        app:tabTextColor="@color/color_secondary_text" />
    
    0 讨论(0)
  • 2020-12-13 02:33

    I know this might be a bit late but here is more simpler code :

    tabLayout.setTabTextColors(getResources().getColor(R.color.blue_200), getResources().getColor(R.color.white));
    

    first value is the default text color, 2nd value is the selected tab text color.

    0 讨论(0)
提交回复
热议问题