Reputation: 1173
I am trying to change the color of my Hello World app.
Right now it looks like this in the emulator (purple bar, pink floating icon):
But when I change the theme setting, I get a bunch of rendering errors (note that I tried to choose Material Light):
And when I try to run the app again it still looks purple/pink as it did in the first pic. I'm not really sure how to make heads or tails of these kinds of errors or how I am supposed to fix them.
Upvotes: 0
Views: 10717
Reputation: 1917
Android Studio Giraffe | 2022.3.1 or Android Studio Giraffe | 2022.3.1
1. color.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#1bade3</color>
<color name="colorPrimaryDark">#000000</color>
<color name="colorAccent">#1bade3</color>
</resources>
2. themes.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MsgShareApp" parent="android:Theme.Material.Light.DarkActionBar" >
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:colorAccent">@color/colorAccent</item>
</style>
</resources>
Upvotes: 0
Reputation: 34532
You are changing the theme of the preview window. This is used to view how your layout would look using a given theme. It does not change the theming on your phone when running your app—it is just a preview.
To actually change the colors you need to change the theme. Usually this would be the AppTheme
that is referencing some colors.
Locate your colors.xml
in res/values/
and modify the colors there:
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
These colors get used by the theme generated at project creation, looking like this in styles.xml
:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
You could also remove the reference and edit the colors in the theme directly, but that is usually not the clean way. Your styles.xml
would also be the right place to add more themes—which in turn you could preview in Android Studio.
Upvotes: 1