preface
Android immersion and full screen are two different themes, so let’s take a look
Android implements full screen
Through the subject property
<style name="FullScreenTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:background">#ff00beb4</item>
</style>Copy the code
Used in androidManifest.xml
<activity android:name=".TestActivity"
android:theme="@style/FullScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>Copy the code
Use full-screen themes
<activity android:name=".TestActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>Copy the code
or
<activity android:name=".TestActivity"
android:theme="@android:style/Theme.Material.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>Copy the code
Java code
requestWindowFeature(Window.FEATURE_NO_TITLE);// This line of code must precede setContentView, otherwise it will blink
setContentView(R.layout.activity_test);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);Copy the code
rendering
Android implements a transparent status bar
Half submerged
<style name="TranslucentTheme">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">#ff00beb4</item>
</style>Copy the code
Use:
<activity android:name=".TestActivity"
android:theme="@style/TranslucentTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>Copy the code
Translucent renderings
Isn’t this all right? But this is a 5.1 system, when switching to a 6.0 later system
Transparent type 6.0
Window window = activity.getWindow();
// This is the best step to do, because the following does not take effect if the two flags are not cleared
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
// The Settings layout can be extended to the StatusBar and NavigationBar
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// set the color of the StatusBar to transparent
window.setStatusBarColor(Color.TRANSPARENT);
// make the NavigationBar color transparent
window.setNavigationBarColor(Color.TRANSPARENT);Copy the code
Add this code and you can see the effect
About the navigation bar SystemUiVisibility
final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE// Keep the system stable
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION// Hide the navigation bar layout, but SYSTEM_UI_FLAG_HIDE_NAVIGATION does not take effect without setting it
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION// Hide the navigation bar
| View.SYSTEM_UI_FLAG_IMMERSIVE// Immersive, will be full screen
/ * | the SYSTEM_UI_FLAG_FULLSCREEN / / full screen | the SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN * /
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY// Viscous immersion, slide down and up to display the status bar and navigation bar
| 0x00200000 |// Hide the navigation bar's Back button
0x00400000 |// Hide the navigation bar home button
0x01000000;// Hide the recent key in the navigation bar
window.getDecorView().setSystemUiVisibility(flags);Copy the code
About fitsSystemWindows
android:fitsSystemWindows=true<! -- Allows your layout to not go to the status bar and navigation bar, but the color will still pass through -->Copy the code