安卓:显示/隐藏状态栏/力量吧 [英] 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.
我已经把在OnCreate
I've put in the onCreate
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
和在按钮 显示:
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);
隐藏:
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);
任何提示/的窍门?
Any hints/tipps?
//修改
我已经看了这个提示在这里: http://android.serverbox.ch/?p=306 并改变了我的code是这样的:
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();
}
所以,如果我点击我的按钮的调用方法我可以看到某些事情正在发生,因为应用程序在等待几秒钟。 我也看了成LockCat,看到某些事情正在发生。
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.
显示: http://pastebin.com/CidTRSTi 隐藏: http://pastebin.com/iPS6Kgbp
推荐答案
你有全屏主题在清单中设置?
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);
这篇关于安卓:显示/隐藏状态栏/力量吧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!