Android设计库TabLayout后台问题
Android design library TabLayout background issues
当我设置“22.2.0 Android 设计库”TabLayout (android.support.design.widget.TabLayout) 的 tabBackground 属性时出现两个问题:
- 选项卡中的涟漪效果消失
- 选项卡指示器消失。
这发生在 Lollipop 和 Kitkat 设备上。
如果不设置 tabBackground,波纹效果和 tab 指示器都可以工作,但背景的默认颜色与 toobar 不同,这不完全符合 material 设计指南。
请在下面找到 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: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" />
当我设置“22.2.0 Android 设计库”TabLayout (android.support.design.widget.TabLayout) 的 tabBackground 属性时出现两个问题:
- 选项卡中的涟漪效果消失
- 选项卡指示器消失。
这发生在 Lollipop 和 Kitkat 设备上。
如果不设置 tabBackground,波纹效果和 tab 指示器都可以工作,但背景的默认颜色与 toobar 不同,这不完全符合 material 设计指南。
请在下面找到 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: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" />