1,横屏切换加此代码:
//获得 WindowManager.LayoutParams 属性对象
WindowManager.LayoutParams lp = getWindow().getAttributes();
//直接对它flags变量操作 LayoutParams.FLAG_FULLSCREEN 表示设置全屏
lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
//设置属性
getWindow().setAttributes(lp);
//意思大致就是 允许窗口扩展到屏幕之外
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
2,竖屏切换代码:
//获得 WindowManager.LayoutParams 属性对象
WindowManager.LayoutParams lp2 = getWindow().getAttributes();
//LayoutParams.FLAG_FULLSCREEN 强制屏幕状态条栏弹出
lp2.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
//设置属性
getWindow().setAttributes(lp2);
//不允许窗口扩展到屏幕之外 clear掉了
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);