i want to make my navigation bar
translucent , so i did some thing like this :
<style name="BlueToolBar" parent="Theme.AppCompat">
<item name="windowActionBar">false</item>
<item name="android:colorBackground">@color/action_blue</item>
<item name="colorPrimary">@color/action_blue</item>
<item name="colorPrimaryDark">@color/status_bar</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
and it is working nicely, but my toolbar and status bar are merged,
when i use this:
<style name="BlueToolBar" parent="Theme.AppCompat">
<item name="windowActionBar">false</item>
<item name="android:colorBackground">@color/action_blue</item>
<item name="colorPrimary">@color/action_blue</item>
<item name="colorPrimaryDark">@color/status_bar</item>
</style>
the resualt is :
there is a better solution:
just set android:fitsSystemWindows="true"
to the xml of your parent layout. the system will take care of setting the proper paddingTop
<item name="android:windowTranslucentNavigation">true</item>
not only makes the Navigationbar translucent, it also causes the activity being drawn behind the statusbar.
To get around this you can set a margin at the top of your toolbar.
Getting the height of the Statusbar can be done via:
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
Now set the margin to the toolbar via this (if your ToolBar is in a LinearLayout):
((LinearLayout.LayoutParams) toolbar.getLayoutParams()).setMargins(0, getStatusBarHeight(this), 0, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With