简体   繁体   English

隐藏状态栏android

[英]Hide status bar android

How to hide status bar android 4.1.2 ? 如何隐藏状态栏android 4.1.2? i want solution to hide the status bar on version 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版

Since Jellybean (4.1) there is a new method that doesn't rely on the WindowManager. 从Jellybean(4.1)开始,有一种新方法不依赖于WindowManager。 Instead use setSystemUiVisibility off of the Window, this gives you more granular control over the system bars than using WindowManager flags. 而是使用窗口的setSystemUiVisibility,这使您可以比使用WindowManager标志更精细地控制系统条。 Here is a full example: 这是一个完整的例子:

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();
    }
}

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 :) 你完成了:)

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);

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); 

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

在onCreate方法中编写此代码

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM