The toolbar is on top of the toolbar. How to fix it?

The toolbar is located on top of the toolbar.

Here is the markup

<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:id="@+id/coordinator" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="112dp" /> <android.support.design.widget.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" > <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|right" android:id="@+id/imageButtonFrame" > <ImageButton android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/imageButton" android:src="@drawable/sa_edit_schedule" android:background="@drawable/schedule_btn" android:padding="@dimen/sa_margin_edit_img" /> </FrameLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|right" android:id="@+id/imageButtonCloseFrame" android:layout_toRightOf="@+id/imageButtonFrame" > <ImageButton android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/imageButtonClose" android:src="@drawable/sa_close_edit_schedule" android:background="@drawable/schedule_btn" android:padding="@dimen/sa_margin_edit_img" /> </FrameLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|right" android:id="@+id/imageButtonCreateFrame" > <ImageButton android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/imageButtonCreate" android:src="@drawable/sa_favorite_create" android:background="@drawable/schedule_btn" android:padding="@dimen/sa_margin_edit_img" /> </FrameLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|right" android:id="@+id/imageButtonDeleteFrame" android:layout_toRightOf="@+id/imageButtonFrame" > <ImageButton android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/imageButtonDelete" android:src="@drawable/sa_favorite_delete" android:background="@drawable/schedule_btn" android:padding="@dimen/sa_margin_edit_img" /> </FrameLayout> </android.support.v7.widget.Toolbar> <android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:tabIndicatorColor="@android:color/background_light" app:tabSelectedTextColor="@android:color/background_light" app:tabTextColor="@android:color/background_light" /> </android.support.design.widget.AppBarLayout> </android.support.design.widget.CoordinatorLayout> 
  • Show the markup - YuriySPb
  • Here is my markup: - Vlad Lynnik
  • Try adding android:fitSystemWindows="true" for AppBarLayout - YuriiSPb
  • It did not help me - Vlad Lynnik
  • Try to add CoordinatorLayout besides AppBarLayout android:fitSystemWindows="true" - Juriy Spb

2 answers 2

I can not understand what you need to fix. Retreat from above is necessary? Try it.

 android:paddingTop="@dimen/activity_vertical_margin" 

in android.support.design.widget.CoordinatorLayout insert.

  • No, it's done without it, you need to play with android:fitSystemWindows="true" - YuriySPb

Try AppBarLayout android:fitSystemWindows="true" for AppBarLayout and CoordinatorLayout android:fitSystemWindows="true"

UPD_0:

You also need the theme of your application to inherit Theme.AppCompat.Light.NoActionBar . Those. in styles.xml :

 <resources> <style name="Base.Theme.Light" parent="Theme.AppCompat.Light.NoActionBar" > </style> </resources> 

And in the manifesto this topic should be indicated:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ru.kuchanov.material" > <application android:theme="@style/Base.Theme.Light" > </application> </manifest> 

Also check whether you setActionBar(toolbar) method in the Toolbar code to the ActionBar th method.

PS Everything mentioned in the response should be used simultaneously. Here is an example application that uses all these things: tyk

  • I tried, nothing happened. What other options are there? Will the changes be visible when viewing the layout inside AndroidStudio? - Vlad Lynnik 2:21 pm
  • @VladLynnik, see the updated answer. And it is better to look at the changes on the device (or emulator), since xs how the layout viewer works with all these new things from google. - Yuriy SPb