【发布时间】:2017-01-06 04:55:11
【问题描述】:
我的主题定义为
<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... ex? -
@Charuka 是同样的错误
-
我们不能在
- 中使用
android:color,我们需要使用android:drawable来设置背景, - 中使用
-
@Charuka 问题是如何定义可绘制的属性颜色,因为我正在更改主题并且每个主题都有单独的颜色。在布局 xml 中它可以工作,但在可绘制 xml 中它没有
标签: java android android-drawable android-styles