5

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 Answers3

11

You can set default Toolbar title as following:

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

For fragment:

getActivity().setTitle("Your Title");
tahsinRupam
  • 6,325
  • 1
  • 18
  • 34
2

getSupportActionBar().setTitle("Title")

Rudrik Patel
  • 676
  • 6
  • 13
0

Set ActionBar title based on your need

ActionBar ab = getActionBar();
ab.setTitle("My Title");
Ramesh sambu
  • 3,577
  • 2
  • 24
  • 39