【发布时间】:2014-01-30 14:14:58
【问题描述】:
我正在开发一个需要全屏模式的应用程序。
我尝试在清单中使用此代码,
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
但什么也没发生,按钮栏(如主页、返回和最近的任务应用程序)仍然存在。我需要隐藏它们才能完全拥有全屏。请帮我解决一下这个。谢谢你。
【问题讨论】:
标签: android
我正在开发一个需要全屏模式的应用程序。
我尝试在清单中使用此代码,
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
但什么也没发生,按钮栏(如主页、返回和最近的任务应用程序)仍然存在。我需要隐藏它们才能完全拥有全屏。请帮我解决一下这个。谢谢你。
【问题讨论】:
标签: android
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
从 API 19 以后,您可以使用SYSTEM_UI_FLAG_IMMERSIVE_STICKY 标志:
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
参见文档here
【讨论】:
尝试在setContentView(R.layout.MainActivity);之前写这段代码
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
这段代码对我有用
【讨论】:
@bladefury 有一个很好的答案,但您可能也想研究一下...
您还在 4.4 KitKat 中描述了一个名为 Immersive Mode 的新功能。
请注意,您需要 API 19 才能对此进行测试。
【讨论】:
经过大量研究,我终于弄明白了,并将我的活动设为全屏模式。
getWindow().getDecorView().setSystemUiVisibility(8);
【讨论】: