I want to add a picture to the download screen for android version 12 and above, the color is set, but for some reason the picture is not visible, everything is fine on versions below 12
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowSplashScreenBackground">#000000</item>
<item name="android:windowSplashScreenAnimatedIcon">
@drawable/splash
</item>
</style>
</resources>
folders with files styles.xml named in the values-v31 style
Starting from Android 12, the splash screen behavior has changed, and it no longer supports displaying an animated icon or drawable directly. Instead, you can customize the splash screen by providing a background color using the android:windowSplashScreenBackground attribute.
To display an image on the splash screen for Android 12 and above, you need to use a different approach. You can create a separate layout file for the splash screen and set it as the window content view for the splash screen activity.
Here's an example of how you can achieve this:
Create a new layout file for the splash screen. Let's name it activity_splash.xml. Place this file in your app's res/layout directory.
In activity_splash.xml, define the layout for the splash screen and add an ImageView to display the image. For example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/splash"
android:scaleType="centerCrop" />
</RelativeLayout>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
// Add any additional logic here
}
}
Remember to replace R.layout.activity_splash with the correct resource ID if necessary.
With this setup, when the app launches, the SplashActivity will be displayed with the image set in the ImageView of activity_splash.xml. You can customize the layout and add any additional logic or transitions as needed
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments