我正在尝试创建一个按钮,可以在平板电脑上隐藏或显示状态栏。
我已经把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);
hide:
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);
有什么提示/技巧吗?
//edit
我在这里查看了这个提示:http://android.serverbox.ch/?p=306 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,发现发生了一些事情。
show: http://pastebin.com/CidTRSTi http://pastebin.com/CidTRSTi
hide: http://pastebin.com/iPS6Kgbp http://pastebin.com/iPS6Kgbp