相关疑难解决方法(0)

如何在我的风格中获得自己定义的属性值

我想使用自定义(自己)属性为对话框创建3个不同的主题.我想通过将其添加到主题的样式来设置标题颜色: <item name="titleColor">#FF0000</item>

我的themes.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>
Run Code Online (Sandbox Code Playgroud)

我在attrs.xml中定义了titleColor属性:

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <declare-styleable name="MyCustomAttributes">
  <attr name="titleColor" format="color|reference" />
 </declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)

我为对话框应用了一个主题.如何将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>
Run Code Online (Sandbox Code Playgroud)

resources android themes coding-style

17
推荐指数
1
解决办法
8108
查看次数

标签 统计

android ×1

coding-style ×1

resources ×1

themes ×1