0

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

1 Answer 1

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"); 
Sign up to request clarification or add additional context in comments.

2 Comments

Really the support.v7.widget.Toolbar? Use androidx package or the material components library.
My bad, I took it from a very old project

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.