Android App startup image pitfalls

The default interface is a blank interface when the Android App is started, and the corresponding layout is displayed after the Activity responsible for starting is ready.

There is a well-known simple solution to this problem, which is to customize the theme of the Activity responsible for starting and add a startup image to it:

In AndroidManifest.xml

<activity
    android:label="@string/app_name"
    android:theme="@style/Theme.AppStartLoad"
    android:name=".StartupActivity" >
    <intent-filter >
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

In styles.xml

The name is consistent with the theme of the above code

<style name="Theme.AppStartLoad" parent="Theme.AppCompat.DayNight.NoActionBar">
		<item name="android:windowBackground">@drawable/loading</item>
		<item name="android:windowNoTitle">true</item>
		<item name="android:statusBarColor">@color/transparent</item>
		<item name="android:navigationBarColor">@color/transparent</item>
	</style>

Then prepare a picture with the file name loading.png (consistent with the windowBackground of the above code)

The pit in question:

There are requirements for the length and width of this loading.png. If it is too small, the startup interface will only display an area as large as this picture (I just discovered this today. It turned out to be a random picture, w*h = 1080*1920 approx. 72KB, I thought it was too big and wanted to change it to a smaller size to save some size, but I found this problem)

Then, I thought about some large-screen mobile phones or even tablets. If the picture is too small, it will be blocked, so I doubled the length and width. The result was shocking: after the phone startup screen was displayed, the startup failed! (The device is Xiaomi Youth 10)

Logcat prompt:

java.lang.RuntimeException: Canvas: trying to draw too large(122412096bytes) bitmap.

Good guy, a 2160*3840 picture is about 213KB. The system draws it in true color very honestly, and the memory is 122M!

Therefore, the length and width of this loading.png cannot be too large or too small. But the length and width of Android devices are so diverse. If you set it to a large size, some devices will not be able to start. If you set it to a small size, some of the devices will block the main interface to the corners.

Solution: In the second method below, you can use a very small picture and fill it with a solid color shape around the picture.

For this app, the gravity of the bitmap can be set to center, and there is no need to set top or the like.

Solve the problem of white screen on Android APP startup page and how to achieve full screen display_white screen on android startup_Sitao's blog's blog-CSDN blog

Guess you like

Origin blog.csdn.net/piggy514/article/details/132270106