Cómo alinear el texto en una barra de pestañas en Android
Quiero poner solamente el texto en la barra de la lengüeta, ninguna imagen … Quiero centrar el texto en una barra de la lengüeta, horizontalmente y verticalmente. Exactamente en el centro.
Usted puede agregar esto al formato de xml android:gravity="center"
o android:layout_gravity="center"
Si alguien sigue interesado en la solución simple sin crear su propio diseño y estilos:
- Use android.widget.TabHost.TabSpec # setIndicator (etiqueta CharSequence) para cada ficha agregada
-
Utilice el siguiente código para centrar y ajustar el texto dentro de la pestaña:
int tabCount = tabHost.getTabWidget().getTabCount(); for (int i = 0; i < tabCount; i++) { final View view = tabHost.getTabWidget().getChildTabViewAt(i); if ( view != null ) { // reduce height of the tab view.getLayoutParams().height *= 0.66; // get title text view final View textView = view.findViewById(android.R.id.title); if ( textView instanceof TextView ) { // just in case check the type // center text ((TextView) textView).setGravity(Gravity.CENTER); // wrap text ((TextView) textView).setSingleLine(false); // explicitly set layout parameters textView.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT; textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT; } } }
¡Intente esto que será ayuda a usted !!!
<?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tabhost" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="1dp" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" > <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="60dp" android:layout_alignParentBottom="true" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="1dp" > </FrameLayout>
<android.support.design.widget.TabLayout app:tabMode="fixed" app:tabContentStart="0dp"