如何使用XML更改TabLayout背景颜色?

问题描述

我正在尝试更改TabLayout的背景颜色,但到目前为止,我尝试过的所有操作均无效。

<com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabIndicatorColor="#FF0000"
        app:tabSelectedTextColor="#FF0000"
        app:tabTextAppearance="@style/TabTextAppearance"
        app:tabTextColor="#FFFFFF">

        <com.google.android.material.tabs.TabItem
            android:id="@+id/tab_one"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tab 1" />

        <com.google.android.material.tabs.TabItem
            android:id="@+id/tab_two"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tab 2" />

我已尝试按照此处的建议使用可绘制(selector):https://stackoverflow.com/a/33230289/12221284

我尝试使用自定义样式扩展TabLayout样式。

我尝试直接在布局文件中设置XML属性

也许我做错了,但到目前为止没有任何效果,我不明白为什么。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)