【问题标题】:How to change Color of the tabStrip in Android?如何在 Android 中更改 tabStrip 的颜色?
【发布时间】:2012-09-02 19:06:20
【问题描述】:
我正在尝试将 tabStrip 的颜色更改为白色,下面的代码不起作用?我做错了什么?
getTabHost().getTabWidget().setLeftStripDrawable(Color.WHITE);
getTabHost().getTabWidget().setRightStripDrawable(Color.WHITE);
getTabHost().getTabWidget().setStripEnabled(true);
【问题讨论】:
标签:
android
android-activity
tabs
android-widget
【解决方案1】:
使用任何可绘制对象代替颜色
表示 setLeftStripDrawable 需要可绘制资源,但您将 int 作为参数。
所以要么在这里使用可绘制的图像。或者使用包含颜色的drawable中的xml。
【解决方案2】:
我希望您想更改标签条背景的颜色。您可以通过创建一个以
为根元素的布局来实现这一点
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>
在您使用标签的 xml 中,您可以按如下方式添加 tab_strip.xml
<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"/>
这将使您的标签条颜色变为白色。
【解决方案3】:
您可以在 Tablayout 中使用 app:tabIndicatorColor="@color/indicator_color 更改颜色。
<android.support.design.widget.TabLayout
app:tabIndicatorColor="@color/indicator_color
/>