【问题标题】:TabLayout color of selected tab underline选定选项卡下划线的 TabLayout 颜色
【发布时间】:2016-12-19 16:18:53
【问题描述】:

如何更改新TabLayout 上选定选项卡下划线的颜色? PagerTabStrip有一个方法setTabIndicatorColor(int color)TabLayout好像没有这个方法。

【问题讨论】:

  • 你看到我的回答了吗?

标签: android android-layout


【解决方案1】:

使用app:tabIndicatorColor

示例:

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabIndicatorColor="@android:color/white" />

确保你有这个namespace:xmlns:app="http://schemas.android.com/apk/res-auto"

文档: https://developer.android.com/reference/android/support/design/widget/TabLayout.html#attr_android.support.design:tabIndicatorColor.

【讨论】:

【解决方案2】:

尝试从这个位置下载以下文件:

https://github.com/google/iosched/tree/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget

SlidingTabLayout.java
SlidingTabStrip.java

尝试以这种方式设置标签指示器颜色:

slidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
     @Override
     public int getIndicatorColor(int position) {
        return getResources().getColor(R.color.color_name);
     }
});

【讨论】:

【解决方案3】:

您可以使用 setcustomTebColorizer 下面是例子

mSlidingTabLayout=(SlidingTabLayout)findViewById(R.id.sliding_tabs);
        mSlidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
            @Override
            public int getIndicatorColor(int position) {
                return Color.YELLOW;
            }

                @Override
                public int getDividerColor(int position) {
                    return 0;
                }
            });

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-10-21
  • 1970-01-01
  • 2016-04-06
  • 2016-03-01
  • 1970-01-01
  • 2013-04-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多