我必须继承一个自定义的主要活动类,它是一个 3rd 方库,我不能对该类进行任何更改。此类将 FLAG_LAYOUT_IN_SCREEN 添加到窗口中,并导致应用程序全屏显示。但是,我想阻止这种行为。那么,问题是如何清除/禁用全屏模式并显示导航栏/状态栏?
这是自定义的主要活动类
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...
}
}
这是我的活动课:
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);
}