I want to create 3 different themes for a dialog using a custom (own) attribute.
I would like to set title colors by adding this to theme’s style:
<item name="titleColor">#FF0000</item>
my 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>
I defined titleColor attribute in attrs.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyCustomAttributes">
<attr name="titleColor" format="color|reference" />
</declare-styleable>
</resources>
I apply one of the themes for the dialog.
How can I pass my titleColor attribute’s value to an “android:color” attribute?
<?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>
?titleColor see here
or
You’d define your colours in the colors.xml file and reference them like a normal resource: @color/MyRed
You’d make a custom attribute for your own views which you want to be customisable from layout xmls. For example, you might extend TextView to write the first line of text in one colour (titleColor) than the rest of the text (android:textColor).