Use style to replace background to prevent activity from flashing on black background 1. The 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=< Span class= "hljs-string" > "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=< Span class= "hljs-string" > "@+id/button3"/></LINEARLAYOUT>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
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) using Stytle