how to set title in toolbar?

6.8k Views Asked by At

Seems pretty simple question, but could't find any answer. How to change the toolbar title.

The toolbar is created by AppCompat Activity,not a custom created one. It has the app name as default.I would like to change its Name corresponding to the action the activity performs.

Note : I can change custom toolbar title using the below code,so please i am not looking for that.

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle("My Title");
3

There are 3 best solutions below

0
tahsinRupam On BEST ANSWER

You can set default Toolbar title as following:

YourActivity.this.setTitle("Your Title");

For fragment:

getActivity().setTitle("Your Title");
0
Ramesh sambu On

Set ActionBar title based on your need

ActionBar ab = getActionBar();
ab.setTitle("My Title");
0
Rudrik Patel On

getSupportActionBar().setTitle("Title")