Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: show/hide status bar/power bar

I am trying to create a button where I can hide or show the status bar on my tablet.

I've put in the onCreate

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); 

and in the buttons show:

WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; getWindow().setAttributes(attrs); 

hide:

WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; getWindow().setAttributes(attrs); 

Any hints/tipps?

//edit

I've looked at this hint here: http://android.serverbox.ch/?p=306 and changed my code like this:

private void hideStatusBar() throws IOException, InterruptedException {     Process proc = Runtime.getRuntime().exec(new String[]{"su","-c","service call activity 79 s16 com.android.systemui"});     proc.waitFor(); }  private void showStatusBar() throws IOException, InterruptedException {     Process proc = Runtime.getRuntime().exec(new String[]{"am","startservice","-n","com.android.systemui/.SystemUIService"});     proc.waitFor(); } 

So if I click on my buttons an the methods are called I can see that something is happening because the app is waiting some seconds. I also looked into LockCat and see that something is happening.

show: http://pastebin.com/CidTRSTi hide: http://pastebin.com/iPS6Kgbp

like image 832
B770 Avatar asked Nov 25 '11 18:11

B770


People also ask

How do I unhide the status bar on Android?

If you want to bring the Notification Bar back, open Fullscreen: The One Immersive Mode again and tap "Hide Nothing." You can also tap the option next to "Fullscreen" to hide your Notification Bar and your Navigation Bar.

Which command is used to hide and Display status bar?

View decorView = getWindow(). getDecorView(); // Hide the status bar.


1 Answers

Do you have the fullscreen theme set in the manifest?

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

I don't think you'll be able to go fullscreen without this.

I would use the following to add and remove the fullscreen flag:

// Hide status bar getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); // Show status bar getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 
like image 200
Rob Avatar answered Sep 27 '22 20:09

Rob