I created the new project with Navigation Drawer from Project Template, and i want to set the title of toolbar on center like this from this
Asked
Active
Viewed 43 times
0
-
5Does this answer your question? [Android toolbar center title and custom font](https://stackoverflow.com/questions/26533510/android-toolbar-center-title-and-custom-font) – Ronak Sethi Jun 18 '20 at 15:50
1 Answers
0
Try this
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="@color/action_bar_bkgnd"
app:theme="@style/ToolBarTheme" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</androidx.appcompat.widget.Toolbar>
In your Activity
Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title);
mTitle.setText("Home");

Hai Hack
- 948
- 13
- 24
-
1Really the support.v7.widget.Toolbar? Use androidx package or the material components library. – Gabriele Mariotti Jun 18 '20 at 15:55
-
1