Android:显示/隐藏状态栏/电源栏
我正在尝试创建一个按钮,可以在平板电脑上隐藏或显示状态栏。
我已经放入 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
您在清单中设置了全屏主题吗?
我认为如果没有这个你就无法全屏显示。
我将使用以下命令添加和删除全屏标志:
Do you have the fullscreen theme set in the manifest?
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:
对于某些人来说,通过清除 FLAG_FULLSCREEN 来显示状态栏可能不起作用,
这是对我有用的解决方案,(文档) (标志参考)
隐藏状态栏
显示状态栏
For Some People, Showing status bar by clearing FLAG_FULLSCREEN may not work,
Here is the solution that worked for me, (Documentation) (Flag Reference)
Hide Status Bar
Show Status Bar
用于android中的kolin
的行尾使用分号(;)
在kolin中隐藏状态栏不需要在android中使用java语言隐藏状态栏
used for kolin in android
for hide status bar in kolin no need to used semicolon(;) at the end of the line
in android using java language for hid status bar
我知道这是一个非常古老的问题,但以防万一有人来到这里寻找最新支持的方式以编程方式隐藏状态栏,您可以按如下方式执行:
并再次显示它:
I know its a very old question, but just in case anyone lands here looking for the newest supported way to hide status bar on the go programmatically, you can do it as follows:
and to show it again:
我已经尝试了很多事情。
最后,这是最适合隐藏和显示全屏模式的代码。
它在此应用程序中实现了它:Android 故障。
转到视频(底部栏)>播放任何视频>切换全屏
I've tried so many things.
Finally, It is the most suitable code to hide and show full screen mode.
It Implemented it in this app : Android Breakdown.
Go to Videos(Bottom Bar) > Play Any Video > Toggle Fullscreen
对于 Kotlin 用户
显示
activity?.window?.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
隐藏
activity?.window? .clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
For Kotlin users
TO SHOW
activity?.window?.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
TO HIDE
activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
使用此方法,使用 SYSTEM_UI_FLAG_IMMERSIVE_STICKY 无需任何实现即可一键返回全屏。只需复制下面的这个方法并在您的活动中您想要的地方调用它即可。
更多详细信息此处
with this method, using SYSTEM_UI_FLAG_IMMERSIVE_STICKY the full screen come back with one tap without any implementation. Just copy past this method below and call it where you want in your activity.
More details here
添加到 XML FitsSystemWindows 参数:
Add to XML fitsSystemWindows parameter:
<RelativeLayout
...
android:fitsSystemWindows="true">
参考 - https://developer.android.com/training/system-ui/immersive .html
Reference - https://developer.android.com/training/system-ui/immersive.html
如果您只想隐藏状态栏,请使用此
If you want to hide only the Status bar, use this