如何动态隐藏状态和导航栏完全?
该应用程序包含一个带有应用程序栏/工具栏和FAB按钮的常规抽屉导航。
切换到全屏时,导航和状态栏的内容会被滚动。屏幕上留下两个空白栏。我要隐藏那些空的酒吧。
我创建了一个minimal demo app。左侧是常规应用。在工厂上推时,该应用应全屏显示。
如何获得隐藏的酒吧?
问题:请写出最小演示项目中需要哪些更改?
更新了第二个解决方案:
@Roaim提供的GREAT解决方案有效。必要的是将android:fitsSystemWindows布局属性设置为false。
如果您仍然无法显示和隐藏状态/导航栏,则此solutin可能会为您提供帮助。
完全隐藏栏:
public static void hideSystemUI() {
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE
| 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
| View.SYSTEM_UI_FLAG_FULLSCREEN);
}
并显示所有条形:
public static void showSystemUI() {
if (getSupportActionBar() != null) {
getSupportActionBar().show();
}
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
最佳答案
更新
问题出在您的布局文件上。我只是设置android:fitsSystemWindows=false
来解决此问题。我为您的仓库做了一个pull request,我认为可以解决您的问题。
您应该遵循以下官方文档:
Hide the Status Bar on Android 4.0 and Lower
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
}
...
}
Hide the Status Bar on Android 4.1 and Higher
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();
Hide the Navigation Bar
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);
关于android-layout - Android-完全隐藏具有抽屉导航和应用程序栏的应用程序的状态和导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61573305/