J'ai créé la barre d'outils personnalisée comme barre d'action de mon activité. Je veux que l'étiquette du titre soit affichée au centre de ma barre d'outils.Comment aligner textview dans le centre de la barre d'outils tout en ajoutant le bouton Précédent dans la barre d'action de soutien
Toolbar fichier de ressources de mise en page est,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_toolbar_select"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
android:src="@drawable/ic_menu_camera" />
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:singleLine="true"
android:text="sample text"
android:textColor="@color/progressWhite"
android:textSize="14sp" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Heading"
android:layout_gravity="center"
android:textColor="@color/progressWhite"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:singleLine="true"
android:text="second line heading"
android:textColor="@color/progressWhite"
android:textSize="12sp"
android:layout_marginBottom="15dp"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
Et mon activité contient,
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar_select_seat);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
Je voulais aligner trois TextView
dans le centre de ma barre d'outils, mais ne pouvait pas être capable d'aligner exactement au centre de ma barre d'outils. Lorsque je lance l'application sur mon appareil, elle n'est pas correctement alignée. Comment pourrais-je résoudre ce problème?
Merci. Ça fonctionne bien! –