简体   繁体   中英

Changing color themes in Android Studio

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM