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:
- ¿Por qué el título no está centrado en la barra de herramientas?
- Fragmento superpone mi barra de herramientas de AppCompat
- Problemas en el uso de nuevo componente de la barra de herramientas, ocultar y mostrar Icono del cajón de navegación, icono de inicio de clic de iconos de fragmentos
- Cómo agregar insignias en la barra de herramientas Iconos MenuItem
- ShowAsAction = "always" se ignora en la barra de herramientas
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?
- ¿Barra de herramientas Android con dos líneas en el título?
- Establecer la altura de la barra de herramientas mediante programación Android
- ¿Puede getSupportActionBar ser nulo justo después de setSupportActionBar?
- Nuevo error de la biblioteca de diseño de Android con AppBarLayout y barra de herramientas
- Título completo de la barra de herramientas
- ¿Cómo hacer que el menú emergente de desbordamiento evite obstruir la barra de acción?
- El título de la barra de herramientas desaparece al agregar vistas
- El reproductor de video apaga el modo en Android usando appcompat-v7
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