How to remove top and bottom padding from android.support.v7.widget.Toolbar file?

I'm trying to post SlidingTabLayout, but for some reason there is an additional top and bottom addition to the portrait layout. As shown in this screenshot:

Portrait

The landscape layout is android.support.v7.widget.Toolbarshorter, and there are no additional indents:

Landscape

I know the attributes contentInsertStartand contentInsetEnd, but for the top and bottom there is nothing. 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 stated in the comments, if I manually set the height from android.support.v7.widget.Toolbarto 48dp, then it will SlidingTabLayoutfill it, but there are two problems here:

  • The toolbar differs from the standard toolbar, which is noticeable when changing actions.
  • The icons in are Toolbarno longer centered vertically if I change the height

, android.support.v7.widget.Toolbar?

+4
1

, @RaviSravanKumar . :

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

    <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="?attr/actionBarPopupTheme"
        >

        <com.myapplication.views.widgets.SlidingTabLayout
            android:id="@+id/sliding_tabs"
            android:layout_width="wrap_content"
            android:layout_height="?attr/actionBarSize"
            />

    </android.support.v7.widget.Toolbar>

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

, ?attr/actionBarSize, , SlidingTabLayout . - , .

, , , ( ). SlidingTabLayout:

:

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTabStrip = new SlidingTabStrip(context);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
}

: ( LayoutParams.WRAP_CONTENT LayoutParams.MATCH_PARENT:

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTabStrip = new SlidingTabStrip(context);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}

:

protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
            outValue, true);
    textView.setBackgroundResource(outValue.resourceId);

    if (Build.VERSION.SDK_INT >= 14) {
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

: ( )

protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
            outValue, true);
    textView.setBackgroundResource(outValue.resourceId);

    if (Build.VERSION.SDK_INT >= 14) {
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, 0, padding, 0);

    return textView;
}
+5

All Articles