Rajat
Rajat

Reputation: 129

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>

Upvotes: 5

Views: 2658

Answers (5)

Rinkesh
Rinkesh

Reputation: 3316

Remove fitSystemWindows Attribute from your theme

<item name="android:fitsSystemWindows">true</item>

Upvotes: 5

ʍѳђઽ૯ท
ʍѳђઽ૯ท

Reputation: 16976

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

I've had the similiar problem, it's working on real devices by the way.

And, Try to use

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

inside your DrawerLayout with that Toolbar inside the AppBarLayout

Check the following links:

http://developer.android.com/training/implementing-navigation/nav-drawer.html#DrawerLayout

To add a navigation drawer, declare your user interface with a DrawerLayout object as the root view of your layout. Inside the DrawerLayout, add one view that contains the main content for the screen (your primary layout when the drawer is hidden) and another view that contains the contents of the navigation drawer.

And, use NavigationView instead of that ListView.

A good example:

http://developer.android.com/intl/es/reference/android/support/design/widget/NavigationView.html

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

     <!-- Your contents -->

     <android.support.design.widget.NavigationView
         android:id="@+id/navigation"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
         android:layout_gravity="start"
         app:menu="@menu/my_navigation_items" />
 </android.support.v4.widget.DrawerLayout>

Upvotes: 0

kevz
kevz

Reputation: 2737

Change your app_bar_main layout as below -

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="com.bits.ketan.geocoding.MainActivity">

    <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" />


</LinearLayout>

Upvotes: 0

Parama Sudha
Parama Sudha

Reputation: 2623

Try this...

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

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

    <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:background="#fff"
            android:choiceMode="singleChoice"
            android:divider="#888"
            android:dividerHeight="1dp" />
        <!--android:listSelector="@drawable/list_selector"-->
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

Upvotes: 0

Daniel Zolnai
Daniel Zolnai

Reputation: 16910

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.

Upvotes: 9

Related Questions