E
E
Evgeny Nizamiev2015-01-05 20:45:25
Android
Evgeny Nizamiev, 2015-01-05 20:45:25

How to change colors depending on the theme?

Such a situation, in the program, you can choose a theme for the program (roughly speaking holo light (by default) or holo dark), and, as I understand it, the colors specified in colors.xml cannot change depending on the selected theme. In the drawable, let's say the background color of the element is described, how to change it if holo dark is selected?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yanchumak, 2015-01-05
@RadiationX

create links in attr.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="titleColor" format="reference|color" />
<attr name="introColor" format="reference|color" />
</resources>

You create your themes with parent android:Theme or holo dark/light as desired already
<style name="AppTheme.MyDark" parent="android:Theme">
   <item name="titleColor">#FFFFFF</item>
   <item name="introColor">#FFFFFF</item>
</style>

<style name="AppTheme.MyLight" parent="android:Theme">
   <item name="titleColor">#000000</item>
   <item name="introColor">#004444</item>
</style

well, in the right ways
TextView
    android:id="@+id/quoteTitle"
    android:textColor="?titleColor"
    ...
</TextView>

example dl.dropbox.com/u/3359186/android_blog/Themes.zip

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question