Search code examples
androidappbar

Set text in the centre of AppBar


I this is my xml:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_height="57dp"
        android:layout_width="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Ranger"
            android:id="@+id/logoSign"/>
    </android.support.design.widget.AppBarLayout>
</RelativeLayout>

I want to do the TextView in the centre of the AppBar. But I get this: enter image description here

Thanks for your help. :)


Solution

  • just use this code for textview

    <TextView
            android:layout_width="match_content"
            android:layout_height="match_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="Ranger"
            android:id="@+id/logoSign"/>