安卓:显示/隐藏状态栏/电源栏

64
我想创建一个按钮,能够在我的平板电脑上隐藏或显示状态栏。我已经放置了在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

11个回答

0

添加到XML的fitsSystemWindows参数:

<RelativeLayout ... android:fitsSystemWindows="true">


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接