I am trying to place a SlidingTabLayout
inside my android.support.v7.widget.Toolbar
but for some reason there is extra top and bottom padding in portrait layout. As shown in this screenshot:
In landscape layout the android.support.v7.widget.Toolbar
is shorter and the extra padding is gone:
I am aware of the contentInsertStart
and contentInsetEnd
attributes but there does not appear to be anything for top and bottom. Here is my layout:
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="?attr/actionBarTheme"
>
<!-- Changing the size of the toolbar fixed the problem below but I don't like the solution since the height difference is perceptible -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
android:padding="0dp"
app:popupTheme="?attr/actionBarPopupTheme"
>
<!-- TODO: BUG - This isn't filling out the action bar in portrait (see note above) -->
<com.myapplication.views.widgets.SlidingTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/pink_400"
/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
As indicated in the comments if I manually set the height of the android.support.v7.widget.Toolbar
to 48dp then the SlidingTabLayout
fills it out but there are two problems here:
- The toolbar is a different height than the standard toolbar which is noticeable when changing activities.
- The icons in the
Toolbar
are no longer vertically centered if I change it's height
So as the title says, how do I remove top and bottom padding from android.support.v7.widget.Toolbar?
Ok so @RaviSravanKumar comment helped me figure this out. When I changed my layout back to:
With the heights set to
?attr/actionBarSize
I noticed theSlidingTabLayout
was actually filling the entire height. I only noticed this because of the pink background I had set for debugging.The reason I missed this originally was because the underline indicator was still not at the bottom (as shown in the screenshot in the original question). I had to make the following changes to the
SlidingTabLayout
code:Original:
New: (note the change from
LayoutParams.WRAP_CONTENT
toLayoutParams.MATCH_PARENT
:Original:
New: (note the change to the layout params and padding)