隐藏状态栏android

时间:2013-11-11 10:34:34

标签: java android android-layout

如何隐藏状态栏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

8 个答案:

答案 0 :(得分:19)

自Jellybean(4.1)以来,有一种新方法不依赖于WindowManager。而是使用窗口的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();
    }
}

答案 1 :(得分:12)

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

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

你完成了:)

答案 2 :(得分:8)

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

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

答案 3 :(得分:3)

希望这是你要找的...在setcontentview之前添加:

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

答案 4 :(得分: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);
  }

答案 5 :(得分:1)

将此代码写入onCreate方法

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

答案 6 :(得分:0)

在此onWindowFocusChanged()方法

中写下这一行
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);

答案 7 :(得分: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);
}