Android Lollipop not showing android:background image

不羁的心 提交于 2019-12-05 04:38:55

Use this theme for your activity in manifest.xml

<style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/primaryColor</item>
        <item name="colorPrimaryDark">@color/primaryColor</item>
        <item name="colorAccent">@color/primaryColor</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="actionMenuTextColor">@android:color/holo_blue_dark</item>
        <item name="android:actionMenuTextColor">@android:color/holo_blue_dark</item>
        <item name="android:windowBackground">@android:color/white</item>
        <item name="android:screenOrientation">portrait</item>
    </style>

and for above API 21 use this create folder in res/values-v21 and use this below theme

<style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/primaryColor</item>
        <item name="colorPrimaryDark">@color/primaryColor</item>
        <item name="colorAccent">@color/primaryColor</item>
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:navigationBarColor">@android:color/black</item>
        <item name="actionMenuTextColor">@android:color/holo_blue_dark</item>
        <item name="android:actionMenuTextColor">@android:color/holo_blue_dark</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/black</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/white</item>
        <item name="android:windowContentTransitions">true</item>
        <item name="android:screenOrientation">portrait</item>
    </style>

Assuming that you're applying your drawable using style, you probably forgot to edit additional style in v21 folder if it exists.

The purpose of mipmap folder is to give android launcher ability to choose different resolution. So put your image back into drawable folder. the better place to put your image within your background is do like this. The main idea is to set your background layer as window resource for login activity.

After long time of test and trial, I finally realized..there is nothing wrong with the code or xml or styling or theme settings.

The little needle in the stack of issue was "Prevent bitmap too large to be uploaded into a texture android"

Reason, when rendering image on Screen OpenGLRenderer was not loading bitmap for high resolution devices and hence no image was coming on nexus devices.

The work around I used was to manually resize the bitmap progrmatically in onCreate() method and set as background for the layout.

Hope it helps for anyone who is not able to load background.

Feel free to query for more!!

A quick fix for this in addition to programmatically resizing the bitmap is just to resize the bitmap externally and place it in a v21 res folder and set it to the background of your view. If there is no prefernce as to how the image should look like accross devices, then just putting it back into the general drawable folder should still work. Manually resizing the bitmap at runtime might be costly unless you randomly change the background image.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!