【发布时间】:2011-11-25 15:41:50
【问题描述】:
我想使用自定义(自己的)属性为对话框创建 3 个不同的主题。
我想通过将其添加到主题样式来设置标题颜色:
<item name="titleColor">#FF0000</item>
我的主题.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme">
<item name="android:alertDialogStyle">@style/dialog</item>
</style>
<style name="MyRedTheme" parent="MyTheme">
<item name="titleColor">#FF0000</item>
</style>
<style name="MyGreenTheme" parent="MyTheme">
<item name="titleColor">#00FF00</item>
</style>
<style name="MyBlueTheme" parent="MyTheme">
<item name="titleColor">#0000FF</item>
</style>
我在 attrs.xml 中定义了 titleColor 属性:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyCustomAttributes">
<attr name="titleColor" format="color|reference" />
</declare-styleable>
</resources>
我为对话框应用了其中一个主题。 如何将我的 titleColor 属性值传递给“android:color”属性?
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.dicare"
android:shape="rectangle">
<solid android:color="I want to pass titleColor value here"/>
</shape>
【问题讨论】:
-
参考这个链接,你可以得到更多关于使用自定义xml属性的想法。HERE
-
我想插入由我的自定义属性定义的值,而不是用新属性扩展视图组件
-
我也有同样的问题。还没找到解决办法
标签: android coding-style resources themes