How to set toolbar title in center in android in JAVA -


this question has answer here:

i know layout way set toolbar title in center. (have textview in toolbar)

i looking java way same. toolbar layout

<android.support.v7.widget.toolbar   android:id="@+id/toolbar"   android:layout_width="match_parent"   android:layout_height="wrap_content"   android:background="@color/colorprimary"   android:minheight="?attr/actionbarsize"> </android.support.v7.widget.toolbar> 

this how setting toolbar title in activity:

toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); getsupportactionbar().settitle("my orders"); getsupportactionbar().setdisplayhomeasupenabled(true); 

title left aligned default.

is there way (without changing layout) make title centered aligned?

toolbar widget can have child views, can used customize , feel of toolbar. the way center text use textview child of toolbar, , customizing it.

<android.support.v7.widget.toolbar     android:id="@+id/toolbar"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:background="@color/colorprimary"     android:minheight="?attr/actionbarsize">      <textview         android:id="@+id/text_view"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center_horizontal"         android:text="@string/app_name"         android:textcolor="@color/black" />  </android.support.v7.widget.toolbar> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -