首页 > 解决方案 > 工具栏内的文本未居中

问题描述

我在XML. 但RelativeLayout不完全适合Toolbar,距离左侧约 10dp。

的代码XML

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@color/colorAccent">

<ImageView
    android:layout_width="35dp"
    android:layout_height="35dp"
    android:src="@drawable/supporter"
    android:layout_alignParentRight="true"
    />

<android.support.v7.widget.AppCompatTextView
    android:id="@+id/title_toolbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fontFamily="@font/yekan"
    android:text="@string/appnameForUsers"
    android:textColor="@android:color/white"
    android:textSize="24sp"
    android:layout_centerHorizontal="true"
    />

<ImageView
    android:layout_width="35dp"
    android:layout_height="35dp"
    android:src="@drawable/supporter"
    android:layout_alignParentLeft="true"
    />

</RelativeLayout>
    </android.support.v7.widget.Toolbar>

标签: androidandroid-layouttoolbar

解决方案


app:contentInsetStart="0dp"

在您的工具栏中添加此属性


推荐阅读