Cómo eliminar el relleno superior y inferior de android.support.v7.widget.Toolbar?

Estoy tratando de colocar un SlidingTabLayout dentro de mi android.support.v7.widget.Toolbar pero por alguna razón hay acolchado superior y inferior extra en el diseño de retrato. Como se muestra en esta captura de pantalla:

Retrato

En la disposición horizontal el android.support.v7.widget.Toolbar es más corto y el relleno adicional se ha ido:

Paisaje

Estoy al tanto de los contentInsertStart y contentInsetEnd pero no parece haber nada para arriba y abajo. Aquí está mi diseño:

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

Como se indica en los comentarios si configuro manualmente la altura del android.support.v7.widget.Toolbar a 48dp, entonces el SlidingTabLayout llena pero hay dos problemas aquí:

  1. La barra de herramientas tiene una altura diferente a la barra de herramientas estándar que se nota cuando se cambian las actividades.
  2. Los iconos de la Toolbar ya no están centrados verticalmente si cambio su altura

Así como el título dice, ¿cómo puedo eliminar el relleno superior y inferior de android.support.v7.widget.Toolbar?

Ok así @RaviSravanKumar comentario me ayudó a averiguar esto. Cuando cambié mi diseño de nuevo a:

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

Con las alturas fijadas en ?attr/actionBarSize noté que el SlidingTabLayout estaba llenando toda la altura. Sólo me di cuenta de esto debido al fondo de color rosa que había establecido para la depuración.

La razón por la que perdí esto originalmente fue porque el indicador de subrayado todavía no estaba en la parte inferior (como se muestra en la captura de pantalla en la pregunta original). Tuve que hacer los siguientes cambios en el código de SlidingTabLayout :

Original:

 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); } 

Nuevo: (tenga en cuenta el cambio de LayoutParams.WRAP_CONTENT a 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); } 

Original:

 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; } 

Nuevo: (tenga en cuenta el cambio a los parámetros de diseño y relleno)

 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; } 
  • La barra de herramientas de Android appcompat se estira cuando se obtiene el enfoque de búsqueda
  • Barra de estado y barra de estado translúcida
  • El efecto de ondulación de fondo en los elementos de la barra de herramientas de StandAlone se ha ido
  • Cómo obtener la barra de herramientas de fragmento?
  • Barra de herramientas Android demasiado alta en modo horizontal
  • Android actionLayout no se muestra con la barra de herramientas
  • Barra de herramientas con modo de pantalla completa inmersiva
  • La barra de herramientas no se desplaza en la barra de estado transparente
  • Los botones de la barra de herramientas no responden al tacto cuando está abierto un cajón de navegación
  • Administrar la barra de herramientas y el botón de retroceso del fragmento en android
  • El espacio entre la navegación hacia arriba y el título de la barra de herramientas es demasiado grande
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.