14

How to hide status bar android 4.1.2 ? i want solution to hide the status bar on version 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

Mohammad Alkhdour
  • 153
  • 1
  • 2
  • 8
  • what do u mean by status bar..Do u mean title bar – Shakeeb Ayaz Nov 11 '13 at 10:42
  • Have a look on [How to hide status bar in Android][1] and [how to hide the status bar without hiding the title bar][2] [1]: http://stackoverflow.com/questions/5431365/how-to-hide-status-bar-in-android [2]: http://stackoverflow.com/questions/6970884/android-how-to-hide-the-status-bar-without-hiding-the-title-bar – Sunil Kumar Sahoo Nov 11 '13 at 10:55
  • thanks,but are not work on version 4.2 – Mohammad Alkhdour Nov 11 '13 at 11:03

8 Answers8

20

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:

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();
    }
}
Robs
  • 8,219
  • 6
  • 41
  • 57
Pete
  • 3,842
  • 3
  • 31
  • 42
  • 2
    useful and hilarious, +1. Btw remember to check whether actionBar is null, just in case if (actionBar != null){ actionBar.hide(); } – Carlos Borau Apr 25 '16 at 14:53
12

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

Jeffy Lazar
  • 1,903
  • 13
  • 20
8

add these lines in oncreate() method

     requestWindowFeature(Window.FEATURE_NO_TITLE);// hide statusbar of Android
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
Shakeeb Ayaz
  • 6,200
  • 6
  • 45
  • 64
Rajiv yadav
  • 823
  • 8
  • 24
3

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

     requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
Amith_Nagraj
  • 231
  • 1
  • 2
  • 9
3

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);
  }
Arpit Patel
  • 7,212
  • 5
  • 56
  • 67
1

Write this code in your onCreate method

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Hitman
  • 588
  • 4
  • 10
0

write the line in this onWindowFocusChanged() method

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
balaji koduri
  • 1,321
  • 9
  • 25
abhishesh
  • 3,246
  • 18
  • 20
0

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);
}
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
janardhan
  • 39
  • 6