Android实现沉浸式状态栏

前段时间,项目中用到了沉浸式的状态栏,在此记录一下,代码如下:

package com.jackie.immersive;

import android.os.Build;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

@Override

public void onWindowFocusChanged(boolean hasFocus) {

super.onWindowFocusChanged(hasFocus);

if (hasFocus && Build.VERSION.SDK_INT >= 19) {

View decorView = getWindow().getDecorView();

decorView.setSystemUiVisibility(

View.SYSTEM_UI_FLAG_LAYOUT_STABLE

| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION

| View.SYSTEM_UI_FLAG_FULLSCREEN

| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

}

}

}

 效果如下:

以上是 Android实现沉浸式状态栏 的全部内容, 来源链接: utcz.com/z/329805.html

回到顶部