Mohammad Alkhdour
Mohammad Alkhdour

Reputation: 153

Hide status bar android

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

Upvotes: 14

Views: 24124

Answers (8)

Pete
Pete

Reputation: 3872

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

Upvotes: 20

janardhan
janardhan

Reputation: 39

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

Upvotes: 0

Arpit Patel
Arpit Patel

Reputation: 8057

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

Upvotes: 3

abhishesh
abhishesh

Reputation: 3316

write the line in this onWindowFocusChanged() method

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

Upvotes: 0

Amith_Nagraj
Amith_Nagraj

Reputation: 231

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

Upvotes: 3

Rajiv yadav
Rajiv yadav

Reputation: 823

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

Upvotes: 8

Jeffy Lazar
Jeffy Lazar

Reputation: 1923

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

Upvotes: 12

Hitman
Hitman

Reputation: 598

Write this code in your onCreate method

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

Upvotes: 1

Related Questions