Android: How to Center title in ToolBar

后端 未结 19 1918
执念已碎
执念已碎 2020-11-27 19:04

I am using ToolBar in my project first time, so i do not know how to customized the toolbar in android. I need to centered title in to the tool bar and how to do that please

相关标签:
19条回答
  • 2020-11-27 19:55

    As far as toolbar is a view group so you can create layouts inside it . Follow these steps

    1-Create a textview inside your Toolbar 2-make your textview gravity center

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" >
    
            <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/profile_image"
                android:layout_width="44dp"
                android:layout_height="55dp"
                android:src="@drawable/profile"
                app:civ_border_color="@color/secondary_text"
                app:civ_border_width="2dp" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Title"
                android:gravity="center"
                style="@style/Base.TextAppearance.AppCompat.Widget.ActionBar.Title"
                />
    
    
        </android.support.v7.widget.Toolbar>
    
    0 讨论(0)
提交回复
热议问题