TabLayout 定制颜色导致编译失败

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabBackground="#ff0000"
    />

报错信息如下:

Android  resource linking failed

counter_fragment_with_tab.xml:12: AAPT: error: '#ff0000' is incompatible with attribute tabBackground (attr) reference [weak].
    
改在color.xml中定义颜色后,问题解决:

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabBackground="@color/colorPrimary"
    />
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#ff0000</color>
</resources>
<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabBackground="@color/colorPrimary"     // TAB 背景的颜色
    app:tabIndicatorColor="@android:color/transparent"   // TAB 下方的划线的颜色
    app:tabTextColor="@color/textColorSecondly"  // TAB 中文字未选中页的颜色
    app:tabSelectedTextColor="@android:color/white"  // TAB 中文字选中页的颜色
    />
 

猜你喜欢

转载自blog.csdn.net/wuzhong8809/article/details/108842126