隐藏和显示状态栏,而对android中的布局没有任何影响 [英] hide and show statusbar without any effect to layout in android

查看:660
本文介绍了隐藏和显示状态栏,而对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:

隐藏通知栏而不使用全屏 隐藏通知栏 Android Show活动标题/状态隐藏后顶部上方的栏

知道怎么做吗?

谢谢

推荐答案

最后,我做到了! 这两种方法将在不破坏布局的情况下显示和隐藏状态栏. 您需要设置

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;

然后

    /** 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);}

   /** Shows StatusBar and ActionBar */
private void showSystemUi() {
    ActionBar ab = getActionBar();
    ab.show();
    // Reset flags 
    mMainView.setSystemUiVisibility(this.mSystemUiVisibility);
}

并将其放在您的onCreate()方法中:

and put this in your onCreate() method:

mMainView = findViewById(R.id.mainLayout);
mMainView.setSystemUiVisibility(mSystemUiVisibility);

这篇关于隐藏和显示状态栏,而对android中的布局没有任何影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆