问题
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?
回答1:
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().
回答2:
<style name="MyCustom_Theme.FullScreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
来源:https://stackoverflow.com/questions/18069660/how-can-i-keep-the-action-title-bar-but-hide-the-notification-bar