[英]hide and show statusbar without any effect to layout in android
I want to write a book-reader application that normally runs in full-screen, but when user touched screen, status bar become visible OVER my main layout without re-creating the whole view. 我想编写一个通常在全屏模式下运行的读书器应用程序,但是当用户触摸屏时,状态栏在我的主布局上变得可见,而无需重新创建整个视图。 I already read these but no help at all:
我已经读过这些,但完全没有帮助:
Hide notification bar without using fullscreen Hide Notification bar Android Show Activity Title/status bar at the top after it is hidden 隐藏通知栏而不使用全屏 显示 隐藏通知栏 Android 隐藏 后在顶部显示活动标题/状态栏
any idea how can I do it? 知道我该怎么办吗?
thanks 谢谢
finally, I did it!! 最后,我做到了! these 2 methods will show and hide status bar without destroying the layout.
这两种方法将显示和隐藏状态栏,而不会破坏布局。 you need to set
你需要设置
private View mMainView; // The main view of the activity
private int mSystemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
then 然后
/** Hides StatusBar and ActionBar */
private void hideSystemUi() {
ActionBar ab = getActionBar();
ab.hide();
// Set flags for hiding status bar
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
// Hide the status bar.
mMainView.setSystemUiVisibility(uiOptions);}
and 和
/** Shows StatusBar and ActionBar */
private void showSystemUi() {
ActionBar ab = getActionBar();
ab.show();
// Reset flags
mMainView.setSystemUiVisibility(this.mSystemUiVisibility);
}
and put this in your onCreate() method: 并将其放在您的onCreate()方法中:
mMainView = findViewById(R.id.mainLayout);
mMainView.setSystemUiVisibility(mSystemUiVisibility);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.