Issue
I have this code that makes the status bar transparent:
private void setTransparentStatusBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
}
But this also makes the navigation bar transparent making my views occupy the space under it like this. Is there any way to make ONLY the status bar transparent?
Solution
From styles.xml you can do the following:
<style name="transparent" parent="Theme.AppCompat.Light">//AppCompat is the key; You can choose any other theme than the light-theme, but stick to AppCompat
<item name="colorPrimaryDark">#00000000</item>//THIS is the important part.
//Other styling(optional)
</style>
What I did was I set colorPrimaryDark to transparent(that is why there are 8 digits instead of 6: transparency is set in the first 2). This sets the color of the statusbar to transparent.
Then to apply it to your layout, simply add the following line in the root layout(view):
android:theme="@style/transparent"
that sets the theme of the layout to the style I showed you above, setting the colorPrimaryDark(the color of the statusbar) to transparent. It still shows things such as the time, notifications, etc, but it has no color.
Now, if you meant hiding the statusbar, you can do it like this:
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
Note that setting it to fullscreen in this manner does NOT hide the navbar. To hide the navbar, you have to look into immersive fullscreen mode.
FINAL NOTE
This final note is to make sure I am in the clear:
If you by navigation bar mean the action bar(the bar with app name/other text at the top of the screen, under the status bar), it is not affected by this. To affect the action bar, change colorPrimary.
IMPORTANT NOTE
Even though you set the bar to transparent, if there is nothing to render underneath, it will show the color of the theme(background color) or black(as there is nothing there, it shows black)
Answered By - Zoe stands with Ukraine
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.