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
1 Answer
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"); 2 Comments
Gabriele Mariotti
Really the support.v7.widget.Toolbar? Use androidx package or the material components library.
Hai Hack
My bad, I took it from a very old project