本文介绍了全屏,无需导航和状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个全屏活动。上面没有像通知栏这样的东西,也没有下面像Home-Button之类的东西。我能够做到这一点,但还想删除home-button栏下面的东西:
这是我的代码。
< style name = MyScreen parent = @ style / Theme.AppCompat.Light>
< item name = windowNoTitle> true< / item>
< item name = windowActionBar> false< / item>
< item name = android:windowFullscreen> true< / item>
< item name = android:windowContentOverlay> @ null< / item>
< / style>
解决方案
您需要的称为
//此代码段隐藏了系统栏。
private void hideSystemUI(){
//设置IMMERSIVE标志。
//将内容设置为显示在系统栏下方,以便在隐藏和显示系统栏时不会调整内容
//的大小。
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLN | ViewAG .SYSTEM_UI_FLAG_FULLSCREEN //隐藏状态栏
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
//此代码段显示系统栏。它通过删除所有标志
//来做到这一点,除了那些使内容显示在系统栏下方的标志。
private void showSystemUI(){
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
I want to create a activity with full screen. Nothing on above like Notification Bar and nothing below like Home-Button etc.I am able to get this, but also wanted to remove below home-button bar:
This is my code.
<style name="MyScreen" parent="@style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
解决方案
What you need is called Immersive Full-Screen Mode.
// This snippet hides the system bars.
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
这篇关于全屏,无需导航和状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!