【问题标题】:Android design library TabLayout background issuesAndroid设计库TabLayout后台问题
【发布时间】:2015-06-20 09:09:53
【问题描述】:

当我设置“22.2.0 Android 设计库”TabLayout (android.support.design.widget.TabLayout) 的tabBackground 属性时出现两个问题:

  • 标签中的涟漪效应消失了
  • 选项卡指示器消失。

这发生在 Lollipop 和 Kitkat 设备上。

如果没有 tabBackground 设置,波纹效果和标签指示器都可以工作,但背景的默认颜色与工具栏不同,这不完全符合材料设计指南。

请在下面找到 XML :

 <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:tabBackground = "?attr/colorPrimary" />

【问题讨论】:

    标签: android ripple android-design-library


    【解决方案1】:

    使用android:background="?attr/colorPrimary" 代替app:tabBackground = "?attr/colorPrimary"

    如果您有深色原色,您可能还想将主题更改为ThemeOverlay.AppCompat.Dark。这会使文本和波纹颜色变为白色。

    完整示例:

    <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark" />
    

    【讨论】:

    • 太棒了。它现在可以工作了,只是我在 KitKat 设备上没有涟漪效应。你知道Android设计库TabLayout中的涟漪效应是否应该移植到KitKat“?谢谢。
    • 我不知道。我认为涟漪仅适用于设计库中的 5.0 及更高版本。
    • android:background="@color/someColor" 也适用于android:theme="@style/ThemeOverlay.AppCompat.Dark",以防有人想知道
    猜你喜欢
    • 1970-01-01
    • 2015-08-12
    • 2015-09-03
    • 1970-01-01
    • 2015-10-10
    • 1970-01-01
    • 2015-08-24
    • 2015-10-19
    • 1970-01-01
    相关资源
    最近更新 更多