1. 程式人生 > >Android動態顯示和隱藏狀態列/實現沉浸式狀態列

Android動態顯示和隱藏狀態列/實現沉浸式狀態列

複製程式碼
   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//設定成全屏模式
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//豎屏
//
設定螢幕為橫屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

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//隱藏nav欄
|View.SYSTEM_UI_FLAG_FULLSCREEN//隱藏狀態列 |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY ); } }
複製程式碼