How to change Color of the tabStrip in Android?

ⅰ亾dé卋堺 提交于 2019-12-11 05:27:06

问题


I am trying to change the color of my tabStrip to white, the code below is not working? What am I doing wrong ?

getTabHost().getTabWidget().setLeftStripDrawable(Color.WHITE);
getTabHost().getTabWidget().setRightStripDrawable(Color.WHITE);
getTabHost().getTabWidget().setStripEnabled(true);

回答1:


Use any drawable instead of color

means setLeftStripDrawable is requiring a drawable resource but you are giving int as a argument.

So either use a drawable image here. Or use a xml from drawable contaning the color.




回答2:


i hope you want to change the color of the background of the tab strip. You could achieve this by creating a layout with a root element as

tab_strip.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF">

</android.support.design.widget.TabLayout>

and in your xml where you are using tab, you could add the tab_strip.xml as follows

<include android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        layout="@layout/tab_strip"/>

And this will make your tab strip colour to white.




回答3:


You can change the color with app:tabIndicatorColor="@color/indicator_color inside the Tablayout.

<android.support.design.widget.TabLayout
    app:tabIndicatorColor="@color/indicator_color
        />


来源:https://stackoverflow.com/questions/12342818/how-to-change-color-of-the-tabstrip-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!