1. 程式人生 > >Android 頁面頂部狀態列隱藏和透明

Android 頁面頂部狀態列隱藏和透明

隱藏

方法1

        //隱藏標題欄
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //隱藏狀態列
        //定義全屏引數
        int flag=WindowManager.LayoutParams.FLAG_FULLSCREEN;
        //獲得當前窗體物件
        Window window=MainActivity.this.getWindow();
        //設定當前窗體為全屏顯示
        window.setFlags(flag, flag);

注意: 設定去標題與設定全屏引數時候一定要在 setContentView(R.layout.activity_main);

之前

方法2

 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

透明

 if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = activity.getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams
.FLAG_TRANSLUCENT_NAVIGATION); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); window.addFlags(WindowManager.LayoutParams
.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.TRANSPARENT); window.setNavigationBarColor(Color.TRANSPARENT); }