简体   繁体   English

如何保留操作/标题栏但隐藏通知栏

[英]How can I keep the action/title bar but hide the notification bar

How can I keep the action/title bar but hide the notification bar? 如何保留操作/标题栏但隐藏通知栏?

This question looks like it has already been answered but most of the answers I found hide both the action bar and the notification bar. 这个问题看起来已经得到了回答,但我找到的大部分答案都隐藏了操作栏和通知栏。 I want to be able to keep the action/title bar. 我希望能够保留动作/标题栏。 The best I've gotten is hiding both and using a linear layout to display a custom action/title bar but I want a system generated one. 我得到的最好的是隐藏它们并使用线性布局来显示自定义动作/标题栏但我想要一个系统生成的。 Also is it possible to hide just the action bar whilst displaying the notification bar? 还可以在显示通知栏时隐藏操作栏吗?

To hide the notification bar use the follow code: 要隐藏通知栏,请使用以下代码:

WindowManager.LayoutParams attrs = act.getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
act.getWindow().setAttributes(attrs);

To show the notification bar use the follow code: 要显示通知栏,请使用以下代码:

WindowManager.LayoutParams attrs = act.getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
act.getWindow().setAttributes(attrs);

You'd probably want to call the code in Activity.onCreate(). 你可能想调用Activity.onCreate()中的代码。

<style name="MyCustom_Theme.FullScreen">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM