Use a style to replace the background to prevent the activity black background from flashing 1. Original layout
<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"Android:layout_width="Match_parent"android:layout_height="Match_parent"Android:background="@drawable/img_bg"android:orientation="Horizontal"> <button android:layout_weight="1"Android:layout_width="0"android:layout_height="Wrap_content"android:text="New button"Android:id="@+id/button2"/> <button android:layout_weight="1"Android:layout_width="0"android:layout_height="Wrap_content"android:text="New Button1"Android:id="@+id/button3"/></linearlayout>
Here we use android:background="@drawable/img_bg" to set the background image, but when we start the activity is sometimes a black background, and then we set the background, to the user feel that our program is running slowly
2. Workaround
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="android:background">@drawable/img_bg</item> </style></resources>
We can set a background for the theme so that it doesn't give the user the impression that our app is jammed
3. Know the reason why
1. Because the subject of the program is loaded when the program starts
The background set in 2.Layout is not loaded until the activity is started
So it will let the user see a black background flashed the process.
Android optimized--ui optimization (iv)