5

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>
Viral Patel
  • 32,418
  • 18
  • 82
  • 110
Rajat
  • 99
  • 1
  • 8
  • Check http://stackoverflow.com/questions/36530906/how-can-i-prevent-the-action-bar-from-being-cut-off?answertab=oldest#tab-top – Munish Thakur May 02 '17 at 08:22
  • http://stackoverflow.com/questions/36530906/how-can-i-prevent-the-action-bar-from-being-cut-off?answertab=oldest#tab-top – Munish Thakur May 02 '17 at 08:24

5 Answers5

8

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.

Daniel Zolnai
  • 16,487
  • 7
  • 59
  • 71
3

Remove fitSystemWindows Attribute from your theme

<item name="android:fitsSystemWindows">true</item>
Rinkesh
  • 3,150
  • 28
  • 32
0

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>
Parama Sudha
  • 2,583
  • 3
  • 29
  • 48
0

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>
kevz
  • 2,727
  • 14
  • 39
0

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>
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108