How to make custom windowBackground theme style work on all Android devices?

后端 未结 2 1190
刺人心
刺人心 2021-01-12 03:34

I am trying to get all of my activities to have a custom theme style that should look like this:

\"good\"

相关标签:
2条回答
  • 2021-01-12 03:55

    I found that the latest version of Android Studio expect that the parent for the style needs to be Theme.AppCompat. Also, it is good style to create a colors.xml file in the values directory (with named color elements between the resource tags). Put your RGB values as values to the named color elements. Reference them in your styles with @color/.

    <!--colors.xml in values folder-->
    <resources>
        <color name="color1">#ffb62a23</color>
        <color name="color2">#ffedeba6</color>
        <color name="color3">#00ff00</color>
    </resources>
    
    <!--style tags -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowBackground">@color/color2</item>
        <item name="android:textColorPrimary">@color/color1</item>
        <item name="android:textColorSecondary">@color/color2</item>
        <item name="android:textColorTertiary">@color/color3</item>
    </style>
    
    0 讨论(0)
  • 2021-01-12 04:00

    The key to solving the problem was changing android:windowBackground in the theme to the following:

    <item name="android:windowBackground">@drawable/default_background</item>
    

    Notice that I am no longer using @color, but simply a @drawable, the xml for which is below:

    <?xml version="1.0" encoding="utf-8"?>
    
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
        <solid android:color="@color/background"/>
    </shape>
    

    It seems that some devices do not support accepting a color for this element.

    0 讨论(0)
提交回复
热议问题