android.support.design.widget.tablayout选项卡指示器颜色
我正在使用TabLayout和视图寻呼机来显示多个选项卡。我想更改所选选项卡指示器。我使用了app:tabIndicatorColor,但颜色没有变化。它呈绿色。我已经了解到,默认情况下,tabIndicator color设置为android.support.design.widget.tablayout选项卡指示器颜色,android,android-layout,android-tablayout,Android,Android Layout,Android Tablayout,我正在使用TabLayout和视图寻呼机来显示多个选项卡。我想更改所选选项卡指示器。我使用了app:tabIndicatorColor,但颜色没有变化。它呈绿色。我已经了解到,默认情况下,tabIndicator color设置为color/accent,但是绿色不是我的accent color。 我的xml如下所示: <?xml version="1.0" encoding="utf-8"?> 您可以尝试为您的表格布局进行以下定制 <android.support.d
color/accent
,但是绿色不是我的accent color。
我的xml如下所示:
<?xml version="1.0" encoding="utf-8"?>
您可以尝试为您的表格布局进行以下定制
<android.support.design.widget.TabLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@id/pages_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorColor="@android:color/white"
app:tabIndicatorHeight="4dp"/>
这应该解决指示灯的颜色问题 根据TabLayout的源代码,tabTextColor必须引用选择器颜色,而不是单一颜色。这是源代码中使用getColorStateList
的部分:
if (a.hasValue(R.styleable.TabLayout_tabTextColor)) {
// If we have an explicit text color set, use it instead
mTabTextColors = a.getColorStateList(R.styleable.TabLayout_tabTextColor);
}
因此,您应该像这样在文件中定义颜色,例如res/color/your_colors.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:color=""@color/primary_light"/>
<item android:color="#0000ff"/>
</selector>
您可以像这样通过编程设置颜色
tabLayout.setSelectedTabIndicatorColor(R.color.black);
看这里:@EranBoudjnah我已经尝试过这个解决方案了。答案正是我上面的代码。您是否尝试过其中一种建议您以编程方式进行更改的解决方案?是的。没有改变任何东西。我们如何在java中设置它?如果您没有阅读最初发布的代码,我已经尝试了app:tabIndicatorColor
如果您想更改指示器的重力,该怎么办?
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
app:tabGravity="fill"
app:tabMode="fixed"
android:background="@color/material_blue_grey_800"
app:tabIndicatorColor="@color/orange"
app:tabSelectedTextColor="@color/orange"
app:tabTextColor="@color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.design.widget.TabLayout>
app:tabIndicatorColor="@color/orange" here is the line which change the color.
tabLayout.setSelectedTabIndicatorColor(R.color.black);