I know the layout way to set toolbar title in center. (Have a TextView in Toolbar)
I am looking for java way for same. This is my 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 is how i am setting toolbar title in activity:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("MY ORDERS");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Title is left aligned by default.
Is there any way (without changing layout) to make title centered aligned?