android:windowBackground not working above android 12 - android

I have a 3 devices, they run from android 10,11 and 12. But the device on android 12 seems to have an issue with windowBackground. I have used the windowBackground as a splashscreen/loadingscreen. This appears to work fine on android 10 and 11 but on android 12 it seems to pick a different image, which I think is my applogo image.
This is the splash_image
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/papaya_orange"/>
<item android:drawable="#drawable/logo_transparant_white_loading_screen"
android:width="250dp"
android:height="95dp"
android:gravity="center" />
</layer-list>
In my styles.xml I have made this:
<style name="LoadingScreen" parent="DarkMode">
<item name="android:windowBackground">#drawable/splash_image</item>
<item name="android:statusBarColor">#color/papaya_orange</item>
</style>
In the manifest I have set the theme to android:theme="#style/LoadingScreen" >
And in my mainactivity I already declared that It switches themes, so nothing wrong there.
So this should work fine, but for some odd reason it doesn't work on android 12 like how it works on 10 and 11. Any guesses on why this doesn't work?

The problem is Android 12 migrations for Splash Screen. Check migration official documentation.

Related

Migration of exisitng splashScreen to Android 12 + is giving distorted splash

We are trying to migrate (because of a crash, that seem related to this - Here's another question for my crash.
Our existing Splash-Screen which also serves as routing.
Previously we used a full screen vector as a theme of splash screen, after following the documentation -
https://developer.android.com/develop/ui/views/launch/splash-screen/migrate#prevent_the_custom_activity_from_displaying
and updated the theme like this -
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenAnimatedIcon">#drawable/ic_launcher</item>
<item name="background">#drawable/background_splash</item>
<item name="postSplashScreenTheme">#style/AppTheme</item>
</style>
background_splash is the drawable image that we want to have in full screen there. Its not working?
Splash screen is looking distorted, the windowSplashScreenAnimatedIcon is cropped and put into a small circle in the center.
Anyone has idea how to achieve this correctly? Thank you for your time!
Is it possible to provide a full screen drawable to splash in accordance with the new splash API for android 12+ with backward compatibility?
Searched for a solution working with Android-12 as well as with older versions and didn't like to create multiple resolution images. Android-12 changed the behaviour of the splash screen (migration guide) but this resulted in a well sized icon either for Android-12 or for earlier versions, but not for both.
Finally I ended up with a trick, to add two splash screen xml files, one for version 12 and higher, the other for all other versions. Give the item (parent of the image) a size in dp, and the bitmap a gravity="fill". The size differs for both splash_screen xml, I don't know if there is an official solution to this problem.
resources/values/styles.xml
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#387aa8</item>
<item name="windowSplashScreenAnimatedIcon">#drawable/splash_screen</item>
<item name="postSplashScreenTheme">#style/MainTheme</item>
</style>
resources/drawable/splash_screen.xml
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:width="224dp" android:height="224dp" android:gravity="center">
<bitmap
android:src="#drawable/silent_notes_256"
android:gravity="fill"/>
</item>
</layer-list>
resources/drawable-v31/splash_screen.xml (Android-12 and higher)
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:width="128dp" android:height="128dp" android:gravity="center">
<bitmap
android:src="#drawable/silent_notes_256"
android:gravity="fill"/>
</item>
</layer-list>
While I did tests with different resolutions, I don't know whether this works for all screen size/resolution combinations.

How to achieve windowSplashScreenBrandingImage in Android below 12 after migrating to new SplashScreen api

I've followed Migrate your splash screen implementation, and it promises that After you migrate using the SplashScreen compat library, the system displays the same splash screen on all versions of Android.
I've created the new splash theme, but the issue is that, I don't have an option to put windowSplashScreenBrandingImage for style belowe values-v31, that is, for android lower than 12.
So the bottom bar that we have been using previously can'be shown as of now.
values-v31/style
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.App.SplashThemeNew" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#android:color/white</item>
<item name="windowSplashScreenAnimatedIcon">#drawable/splash_icon</item>
<item name="android:windowSplashScreenBrandingImage">
#drawable/background_splash_12_bottom_strp
</item>
<item name="postSplashScreenTheme">#style/AppTheme</item>
</style>
</resources>
style
<style name="Theme.App.SplashThemeNew" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#color/white</item>
<item name="windowSplashScreenAnimatedIcon">#drawable/splash_icon</item>
<item name="postSplashScreenTheme">#style/AppTheme</item>
</style>
While according to the Migration guide, it should be possible, Has anyone some ideas about this?
Thanks for your time and attention.
Unfortunately it is not possible to use the android:windowSplashScreenBrandingImage on api lower than 31. This issue has officially been reported as a feature request on the IssueTracker, but for now they say that it won't be implemented (Source). However, it is still assigned so it might get implemented in the future.
Besides that, the Android docs state that The design guidelines recommend against using a branding image.
That being said, I found an Medium article that might help you achieve what you are looking for.

When targeting API 26, overflow menu items become invisible

I have an options menu in my app, which has more than six items, so there is a "More" item that brings up the overflow menu. The menu is posted by the default menu triggers, and a custom trigger that invokes Activity.openOptionsMenu().
The menu itself is built from this resource file:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/mi_copy"
android:title="Copy"
android:icon="#drawable/copy"/>
<item android:id="#+id/mi_paste"
android:title="Paste"
android:icon="#drawable/paste"/>
<item android:id="#+id/mi_preferences"
android:title="Preferences"
android:icon="#android:drawable/ic_menu_preferences"/>
<item android:id="#+id/mi_flip_calc_printout"
android:title="Print-Out"
android:icon="#drawable/printer"/>
<item android:id="#+id/mi_clear_printout"
android:title="Clear Print-Out"
android:icon="#android:drawable/ic_menu_close_clear_cancel"/>
<item android:id="#+id/mi_about"
android:title="About Free42"/>
<item android:id="#+id/mi_import"
android:title="Import Programs"/>
<item android:id="#+id/mi_export"
android:title="Export Programs"/>
</menu>
So far, so good. The menu and the Java logic that creates and posts it has worked for years, but now I'm changing the targetSdkVersion from API level 8 to 26, per the latest Play requirements, and now all of a sudden, the menu items in the overflow menu have become invisible.
The overflow menu still posts, and it still has the correct size, and the menu items still work. You just can't see them any more: the whole menu is solid black now, which is the normal background color; the menu item text is missing.
The phone on which I'm testing is a Motorola G5 running Android 8.1.0. This is the only device I have available for testing with API 26 at the moment, at least until I figure out how to create an AVD with API >= 26.
N.B. In the Android simulator with an API level 8 image, the overflow menu still looks fine. It used to look fine on the Moto G5 as well, before I targeted API 26. If I change the target back to 8, the overflow menu works again.
Any thoughts on what I could do to fix this? My Google skills aren't working on this one... Any ideas would be most welcome!
I added this style file as res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Free42Theme" parent="android:style/Theme.NoTitleBar">
<item name="android:itemBackground">#android:color/white</item>
</style>
<style name="Free42Theme.Fullscreen" parent="android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:itemBackground">#android:color/white</item>
</style>
</resources>
The first is the default theme, specified by changing the android:theme attribute on the Activity from #android:style/Theme.NoTitleBar to #style/Free42Theme in AndroidManifest.xml; the second is the full-screen theme, set in the Java code, by changing the setTheme(android.R.style.Theme_NoTitleBar_Fullscreen) call to setTheme(R.style.Free42Theme_Fullscreen).
This changes the background of the overflow menu to white, making the black item text visible, verified on my G5. Running in the simulator with Android 2.2 (API level 8), the appearance is unchanged since the background was white there from the start.
Many thanks to SteelToe for getting me on the right track!

Spinner background is not correct on Android 6.0+

I use Android project(old project) on Eclipse.
I install ADT from here:
https://dl-ssl.google.com/android/eclipse/
In my manifest.xml
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
snippet of xml layout:
<Spinner
android:id="#+id/currencySpinner"
style="#style/racommon_spinner_custom_style"
android:layout_width="0dip"
android:layout_height="40dip"
android:layout_weight="0.3"
android:prompt="#string/currency" />
here styles.xml
<style name="racommon_spinner_custom_style" parent="#android:style/Widget.Holo.Light.Spinner">
<item name="android:background">#drawable/racommon_spinner_custom_bg</item>
<item name="android:clickable">true</item>
</style>
Here drawable racommon_spinner_custom_bg:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="#drawable/spinner_selected_custom_border"/>
<item android:state_focused="true" android:state_pressed="true" android:drawable="#drawable/spinner_pressed_custom"/>
<item android:drawable="#drawable/spinner_default_custom" />
</selector>
here res\drawable-mdpi\spinner_pressed_custom.9.png
Here result on Android 4.3
and here result on Android 6.0+
Here when click on spinner:
As you can see the background of spinner is different than on Android 4.0. On android 4.0. is correct spinner's background. But in android 6.0+ not correct.
Here result nine-pathch generator
Why?
I think its a problem of dpi, so i would suggest you make 9 patch image according to dpi
go to Below Link
Click Here
and Drag your current 9 patch image here, it will generate the images according to dpi.
Since you aren't setting gradient background programmatically, the problem is just with the style used from deprecated theme: Widget.Holo.Light.Spinner.
Just replace it with up to date theme like Widget.AppCompat.Light.Spinner.
Also you can try just to update targetSdkVersion and use more recent SDK version if that's an option for you.
Some clarification:
the actual cause of the gradients to be broken on newer Android versions is the new requirement to specify values in dp, see Android Gradient on Lollipop not working. - API 21

ActionBarSherlock background does not repeat on pre ICS versions

I'm moving my app's ActionBar to ActionBarSherlock and I'm trying to customize the background with a tiled background. I'm testing my code on 2 real devices, one running Android 2.1 and the other running Android 4.0.4.
The code below is working on the ICS device (the background does repeat) but not on the Eclair one (the background is stretched instead of repeating). I've also tested this on Android 2.3 emulator and the background does not repeat too. It seems the tileMode="repeat" is only working on ICS.
themes.xml:
<style name="Theme.Opheodrys.Base" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/Opheodrys.Widget.ActionBar</item>
<item name="actionBarStyle">#style/Opheodrys.Widget.ActionBar</item>
</style>
<style name="Opheodrys.Widget.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:background">#drawable/ab_background_pattern</item>
<item name="background">#drawable/ab_background_pattern</item>
</style>
ab_background_pattern.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/ab_background_tile"
android:tileMode="repeat"
tileMode="repeat" /> <!-- I've added this just in case, but it doesn't seem to be needed -->
This is Android bug #15340 and not an ActionBarSherlock bug.
You can fix this with something similar to:
BitmapDrawable bg = (BitmapDrawable)getResources().getDrawable(R.drawable.bg_striped);
bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
getSupportActionBar().setBackgroundDrawable(bg);

Categories

Resources