更改 TabLayout(android.support.design.widget) 的选定选项卡指示器颜色
change the selected tab indicator color of TabLayout(android.support.design.widget)
我正在尝试更改 android.support.design.widget.TabLayout
的选定选项卡颜色,我面临的问题是找不到方法 setSelectedTabIndicatorColor
。在 documentation 中提到了它,但在代码中它说它无法解决。我可以使用 app:tabIndicatorColor="@color/red"
更改 xml 中的颜色,但我不知道如何在 JAVA 中更改它。如果我进入 TabLayout class,此方法与 TabLayout.SlidingTabStrip
一起使用,但没有 getter 来获取条带并设置颜色。
有人知道怎么做吗?
您可以通过以下代码更改滑动标签的颜色
试试这个
mTabHost.getTabWidget().getChildAt(0).getBackground().setColorFilter(getResources().getColor(your color), PorterDuff.Mode.SRC);
我不能发表评论所以我会在这里添加。
更新设计支持库,您将看到 setSelectedTabIndicatorColor()
方法。
这是我 build.gradle
中的行:
compile 'com.android.support:design:23.1.0'
我正在尝试更改 android.support.design.widget.TabLayout
的选定选项卡颜色,我面临的问题是找不到方法 setSelectedTabIndicatorColor
。在 documentation 中提到了它,但在代码中它说它无法解决。我可以使用 app:tabIndicatorColor="@color/red"
更改 xml 中的颜色,但我不知道如何在 JAVA 中更改它。如果我进入 TabLayout class,此方法与 TabLayout.SlidingTabStrip
一起使用,但没有 getter 来获取条带并设置颜色。
有人知道怎么做吗?
您可以通过以下代码更改滑动标签的颜色
试试这个
mTabHost.getTabWidget().getChildAt(0).getBackground().setColorFilter(getResources().getColor(your color), PorterDuff.Mode.SRC);
我不能发表评论所以我会在这里添加。
更新设计支持库,您将看到 setSelectedTabIndicatorColor()
方法。
这是我 build.gradle
中的行:
compile 'com.android.support:design:23.1.0'