Problem encountered: Although the status bar is hidden, the original status bar location is occupied by a black bar.
The solution
- In order to achieve a full screen display, set a theme style
<style name="FullTheme" parent="Theme.AppCompat.Light.NoActionBar"> <! -- whether the status bar is set top transparent - > < item name = "android: windowTranslucentStatus" > false < / item > <! - the Android 5. X began to need to set the color transparent, or the top navigation bar will present the light grey system default - > < item name = "Android: statusBarColor" > @ Android: color/transparent < / item > <! - sets whether the navigation bar at the top of the status bar and bottom to transparent - > < item name = "android: windowTranslucentNavigation" > true < / item > < item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> <item name="android:windowFullscreen">true</item> </style>Copy the code
- AndroidManifest.xml
<activity
android:theme="@style/FullTheme"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Copy the code
- In super MainActivity. OnCreate (savedInstanceState); Call hideStatusBar hideBottomUIMenu () ()
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { hideStatusBar(); hideBottomUIMenu(); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } / hide status bar * * * * / protected void hideStatusBar () {WindowManager. LayoutParams lp = getWindow (). The getAttributes (); lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; getWindow().setAttributes(lp); } /** * hide virtual keys, */ protected void hideBottomUIMenu() { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { View v = this.getWindow().getDecorView(); v.setSystemUiVisibility(View.GONE); } else if (Build.VERSION.SDK_INT >= 19) { View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY ; decorView.setSystemUiVisibility(uiOptions); }}}Copy the code