我已经定义了我的主题为:
<style name="AppThemeRed" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimaryRed</item>
<item name="colorPrimaryDark">@color/colorPrimaryDarkRed</item>
<item name="colorAccent">@color/colorAccentRed</item>
</style>
在我的XML布局中,我正在进行以下操作:
<android.support.design.widget.AppBarLayout
android:background="?attr/colorPrimary"
android:id="@+id/topBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
无论我更改哪个主题,colorPrimary 颜色都会改变。 但是,如果我在 drawable 中添加相同的内容。
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="?attr/colorPrimary" />
<corners android:radius="5dp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="?attr/colorPrimary" />
<corners android:radius="5dp"/>
</shape>
</item>
</selector>
出现"无法填充视图"错误,该视图的背景被设置为@drawabe/xxxx
我该如何在我的XML drawable中定义主题颜色属性?
android.view.InflateException: Binary XML file line
... 的异常? - Charuකandroid:color
,需要使用android:drawable
来设置背景。 - Charuක