在 Android 中设置 FLAG_LAYOUT_IN_SCREEN 后禁用全屏模式
Disable fullscreen mode after setting FLAG_LAYOUT_IN_SCREEN in Android
我必须继承自定义主 activity class,这是一个第 3 方库,我无法对 class 进行任何更改。此 class 将 FLAG_LAYOUT_IN_SCREEN 添加到 window 并导致应用全屏显示。但是,我想阻止这种行为。所以,问题是我如何才能clear/disable全屏模式并且可以显示导航bar/status栏?
这里是自定义主程序activityclass
public class CustomActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
setContentView(new FrameLayout(this));
// rest...
}
}
这是我的 activity class:
public class MyActivity extends CustomActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// tried these attempts below, but none of them prevented
// the fullscreen mode which hides navigation bar and status bar.
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}
注意:您也可以轻松地在示例应用程序上对其进行测试。您会注意到,添加 FLAG_LAYOUT_IN_SCREEN
后,全屏模式也会保持不同的尝试。
public class MainActivity extends Activity {
private FrameLayout mainLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().addFlags(FLAG_LAYOUT_IN_SCREEN);
setContentView(new FrameLayout(this));
this.getWindow().clearFlags(FLAG_LAYOUT_IN_SCREEN);
this.getWindow().addFlags(FLAG_KEEP_SCREEN_ON);
}
请将以下内容应用于应用程序,使其不全屏(显示状态栏)
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
我必须继承自定义主 activity class,这是一个第 3 方库,我无法对 class 进行任何更改。此 class 将 FLAG_LAYOUT_IN_SCREEN 添加到 window 并导致应用全屏显示。但是,我想阻止这种行为。所以,问题是我如何才能clear/disable全屏模式并且可以显示导航bar/status栏?
这里是自定义主程序activityclass
public class CustomActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
setContentView(new FrameLayout(this));
// rest...
}
}
这是我的 activity class:
public class MyActivity extends CustomActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// tried these attempts below, but none of them prevented
// the fullscreen mode which hides navigation bar and status bar.
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}
注意:您也可以轻松地在示例应用程序上对其进行测试。您会注意到,添加 FLAG_LAYOUT_IN_SCREEN
后,全屏模式也会保持不同的尝试。
public class MainActivity extends Activity {
private FrameLayout mainLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().addFlags(FLAG_LAYOUT_IN_SCREEN);
setContentView(new FrameLayout(this));
this.getWindow().clearFlags(FLAG_LAYOUT_IN_SCREEN);
this.getWindow().addFlags(FLAG_KEEP_SCREEN_ON);
}
请将以下内容应用于应用程序,使其不全屏(显示状态栏)
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);