Android全屏與非全屏的切換設置方法小結

1. Window方式

if (mIsFullScreen){//設置爲非全屏
    WindowManager.LayoutParams lp = getWindow().getAttributes();
    lp.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().setAttributes(lp);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}else{//設置爲全屏
    WindowManager.LayoutParams lp = getWindow().getAttributes();
    lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    getWindow().setAttributes(lp);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

2. View方式

if (mIsFullScreen){//設置爲非全屏
    getWindow().getDecorView().
    setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}else{//設置爲全屏
    getWindow().getDecorView().
    setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章