简体   繁体   中英

Android - gray background instead of white

Each "layout" I set a white background and "Manifest" I set Theme.Light. Still receives a gray background instead of white. Why?

Edit:

Manifest.xml

android:theme="@android:style/Theme.Light.NoTitleBar">

Layout

android:background="@android:color/white" 

Theme.Light does not mean that it will be white. It just means that it will be light, not dark :P This is not theme.white.

Each device manufacturer can customize Android OS on his phone for example to preferred colors and look & feel. In particular he can define styles for his Android implementation - Light and dark. Thanks to that your app may look differently on various devices, however it will always fit the style used on this device (every app in style Theme.Light will have grey background on this device, unless you set android:background="@android:color/white" )

Your device's manufacturer defined style Theme.Light as style with grey background.

Hope that I am clear - otherwise do not hesitate to ask

I had the same issue until I changed @android:color/white to explicit android:background="#FFFFFF" . Weird though...

Since it's an old question this might have another solution already but anyway one can just enter the AppTheme style tag in styles.xml, you can do so by pressing the ⌘cmd key and clicking on your theme declaration in the manifest.

Over there add this line with your preferred color -

<item name="android:windowBackground">@color/white</item>

This line basically overrides the theme's default background value.

Example -

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:colorControlActivated">@color/black</item>
    <item name="android:windowBackground">@color/white</item>
</style>

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