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().

其他提示

<style name="MyCustom_Theme.FullScreen">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top