我正在尝试创建一个按钮,我可以在其中隐藏或显示平板电脑上的状态栏。
我已经加入了 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);
任何提示/提示?
//编辑
我在这里看到了这个提示:http://android.serverbox.ch/?p=306 并像这样更改了我的代码:
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,发现发生了一些事情。
显示:http://pastebin.com/CidTRSTi 隐藏:http://pastebin.com/iPS6Kgbp
最佳答案
您是否在 list 中设置了全屏主题?
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
如果没有这个,我认为你将无法全屏显示。
我将使用以下内容来添加和删除全屏标志:
// Hide status bar
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Show status bar
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
关于Android:显示/隐藏状态栏/电源栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8273186/