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:
- Barra de herramientas transparente para la barra de herramientas de despliegue agotada
- Establecer la altura de la barra de herramientas mediante programación Android
- Cambiar el ícono de la hamburguesa del cajón de navegación
- Bloquear desplazamiento junto con Expand / Collapse Collapsible Toolbar
- Inflando AppBarLayout con la barra de herramientas + TabLayout
En la disposición horizontal el android.support.v7.widget.Toolbar
es más corto y el relleno adicional se ha ido:
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í:
- La barra de herramientas tiene una altura diferente a la barra de herramientas estándar que se nota cuando se cambian las actividades.
- 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?
- Adición de vista personalizada a una barra de herramientas
- Ocultar barra de herramientas con CoordinatorLayout, pero RecyclerView en un fragmento
- AppBarLayout con contenedor FrameLayout como contenido de desplazamiento no funciona
- La barra de herramientas de la ocultación de AppBarLayout se oculta
- Empuja los iconos hacia afuera cuando se expanda la vista de búsqueda en la barra de herramientas de Android
- No se permite el diseño relativo en la barra de herramientas
- Desactivar la hamburguesa para animar la flecha hacia atrás en la barra de herramientas
- CollapsingToolBarLayout - barra de estado
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; }
- Retrofit: 500 error de servidor interno
- Excepción grave: java.lang.SecurityException: Falta permiso para insertar credenciales