Java 隐藏状态栏android

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19904166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 21:12:33  来源:igfitidea点击:

Hide status bar android

javaandroidandroid-layout

提问by Mohammad Alkhdour

How to hide status bar android 4.1.2 ? i want solution to hide the status bar on version 4.1.2

如何隐藏状态栏android 4.1.2?我想要在 4.1.2 版本上隐藏状态栏的解决方案

i want to hide status bar on my application

我想在我的应用程序上隐藏状态栏

LinearLayout layout = (LinearLayout)findViewById(R.id.layout);    
layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

this code not work on version 4.1.2

此代码不适用于 4.1.2 版

回答by Hitman

Write this code in your onCreate method

在您的 onCreate 方法中编写此代码

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

回答by Rajiv yadav

add these lines in oncreate() method

在 oncreate() 方法中添加这些行

     requestWindowFeature(Window.FEATURE_NO_TITLE);// hide statusbar of Android
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

回答by Jeffy Lazar

Add this to your manifest file under the activity tag in which you want to hide status bar

将此添加到您要隐藏状态栏的活动标签下的清单文件中

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 

and you are done :)

你就完成了:)

回答by Amith_Nagraj

Hope this is what you are looking for.. add this before setcontentview :

希望这是你正在寻找的......在 setcontentview 之前添加这个:

     requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

回答by Pete

Since Jellybean (4.1) there is a new method that doesn't rely on the WindowManager. Instead use setSystemUiVisibility off of the Window, this gives you more granular control over the system bars than using WindowManager flags. Here is a full example:

从 Jellybean (4.1) 开始,有一个不依赖于 WindowManager 的新方法。而是在 Window 之外使用 setSystemUiVisibility,与使用 WindowManager 标志相比,这可以让您对系统栏进行更精细的控制。这是一个完整的例子:

if (Build.VERSION.SDK_INT < 16) { //ye olde method
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else { // Jellybean and up, new hotness
    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();
    if(actionBar != null) {
         actionBar.hide();
    }
}

回答by abhishesh

write the line in this onWindowFocusChanged()method

在这个onWindowFocusChanged()方法中写一行

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);

回答by Arpit Patel

I think this will work

我认为这会奏效

 public static void hideStatusBar(Activity activity) {
    WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
    attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
    activity.getWindow().setAttributes(attrs);
    activity.getWindow().clearFlags(
        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
  }



public static void showStatusBar(Activity activity) {
    WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
    attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    activity.getWindow().setAttributes(attrs);
    activity.getWindow().addFlags(
        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
  }

回答by janardhan

This works for me:

这对我有用:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_splash);
}