I am trying to make a transparant toolbar for my app. I now use windowTranslucentStatus
to achieve this. My problem is now that my statusbar is over my toolbar. I guess I need to give my toolbar a margin top with the height of the statusbar. How can do I know what the height of the statusbar is?
My layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activites.DealersActivity_">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/toolbar" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</RelativeLayout>
</LinearLayout>
<include layout="@layout/drawer"
android:id="@+id/drawer"
></include>
</android.support.v4.widget.DrawerLayout>
My Toolbar:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="@drawable/toolbar_background">
<TextView
android:visibility="gone"
android:typeface="monospace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:textSize="20sp"
android:textColor="@color/toolbar_text"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
After your explanations, it also seems to me that you need to set margin in your toolbar.
Regretfully, I am not aware of a way to determine the height of a status bar in the layout xml (e.g. like
"?attr/actionBarSize"
). However, you can determine it in the code: see here.When you get the height programatically, you would like to change the padding of your toolbar programatically too. Use this method to do it.