Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why android toolbar height is cut?

I am new to the design pattern in latest android studio,the one with include tag.I tried tweaking the files but ended up with cut toolbar.

First Activity

enter image description here

first_activity.xml

 <?xml version="1.0" encoding="utf-8"?>

 <LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="match_parent" android:layout_width="match_parent"
 android:orientation="vertical">

   <include layout="@layout/app_bar_main" android:layout_width="match_parent"
    android:layout_height="wrap_content" />

  <android.support.v4.widget.DrawerLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/drawer_layout"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:fitsSystemWindows="true"
 tools:openDrawer="start">

 <!-- Framelayout to display Fragments -->
 <FrameLayout
     android:id="@+id/frame_container"
     android:layout_width="match_parent"
     android:layout_height="match_parent" />

 <!-- Listview to display slider menu -->
 <ListView
     android:id="@+id/main_nav_drawer"
     android:layout_width="240dp"
     android:layout_height="match_parent"
     android:layout_gravity="start"
     android:choiceMode="singleChoice"
     android:divider="#888"
     android:dividerHeight="1dp"
     android:background="#fff"/>
     <!--android:listSelector="@drawable/list_selector"-->
      </android.support.v4.widget.DrawerLayout> </LinearLayout>

Here's my app bar layout.

app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".Activities.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/AppTheme.AppBarOverlay">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>

    </android.support.design.widget.AppBarLayout>


</android.support.design.widget.CoordinatorLayout>
like image 970
Rajat Avatar asked Jan 20 '16 10:01

Rajat


2 Answers

Change your toolbar XML this way:

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"/>

Notice that minHeight disallows smaller sizes, and the wrap_content height now allows bigger toolbars.

like image 189
Daniel Zolnai Avatar answered Oct 13 '22 07:10

Daniel Zolnai


Remove fitSystemWindows Attribute from your theme

<item name="android:fitsSystemWindows">true</item>
like image 25
rinkesh Avatar answered Oct 13 '22 09:10

rinkesh