动态设置全屏,退出全屏

实现全屏:

private void setFullScreen(){ 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 
}

退出全屏:

方法一:

getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);

方法二:

private void quitFullScreen(){ 
    final WindowManager.LayoutParams attrs = getWindow().getAttributes(); 
    attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    getWindow().setAttributes(attrs); 
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); 
}

个人项目中实现:

/**设置全屏**/
WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(params);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

/**退出全屏**/
WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(params);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);





你可能感兴趣的:(android,动态,全屏)