Android - How to center a title (TextView) in a toolbar?

只谈情不闲聊 提交于 2019-12-01 23:02:15

There are a couple of ways to solve your problem. The quickest one would be to change your TextView as follows.

<TextView
            android:id="@+id/toolbar_title"
            android:layout_width="match_parent" // Fill parent
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Sign Up"
            android:gravity="center" // Make the text center aligned
            android:textColor="#ffffff"
            android:textSize="21dp"
            android:textStyle="bold" />
    </LinearLayout>

This makes sure that your text would cover the entire space next to the icon and center the text within it. You dont even need a LinearLayout for that. It can be removed and it'll still work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!