14

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

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

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

此代码不适用于版本 4.1.2

4

8 回答 8

20

由于 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();
    }
}
于 2014-01-22T02:55:46.000 回答
12

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

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

你完成了:)

于 2013-11-11T10:41:42.707 回答
8

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

     requestWindowFeature(Window.FEATURE_NO_TITLE);// hide statusbar of Android
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
于 2013-11-11T10:41:31.453 回答
3

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

     requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
于 2013-11-11T10:45:37.823 回答
3

我认为这会奏效

 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);
  }
于 2016-02-08T12:02:58.777 回答
1

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

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
于 2013-11-11T10:39:01.250 回答
0

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

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
于 2014-05-23T16:23:39.687 回答
0

这对我有用:

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);
}
于 2017-01-27T12:20:01.767 回答