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

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -