Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toolbar overlapping below status bar

I want to have appcompat v21 toolbar in my activity. But the toolbar I'm implementing is overlapping below status bar. How can I fix it?

overlapping toolbar

Here is the activity layout xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:orientation="vertical">      <include         android:id="@+id/toolbar"         layout="@layout/toolbar" />      <FrameLayout         android:id="@+id/container"         android:layout_width="fill_parent"         android:layout_height="0dp"         android:layout_weight="1" /> </LinearLayout> 

Toolbar view:

<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/toolbar"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:minHeight="?attr/actionBarSize"     android:background="?attr/colorPrimary" /> 

Theme style:

<style name="AppTheme" parent="MaterialNavigationDrawerTheme.Light.DarkActionBar">     <item name="colorPrimary">@color/primary</item>     <item name="colorPrimaryDark">@color/primary_dark</item>     <item name="colorAccent">@color/accent</item> </style> 
like image 756
emen Avatar asked Apr 20 '15 02:04

emen


People also ask

What is fitsSystemWindows in android?

That's what the default behavior of the android:fitsSystemWindows=“true” attribute gives you: it sets the padding of the View to ensure the contents don't overlay the system windows.

What is the height of status bar in Android?

Official height is 24dp , as is stated officially by Google on Android Design webpage.


1 Answers

Use android:fitsSystemWindows="true" in the root view of your layout (LinearLayout in your case). And android:fitsSystemWindows is an

internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows. Will only take effect if this view is in a non-embedded activity.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol fitsSystemWindows.

like image 124
Sohaib Avatar answered Sep 28 '22 23:09

Sohaib