user8660130
user8660130

Reputation:

how to set title in toolbar?

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");

Upvotes: 5

Views: 6953

Answers (3)

Rudrik Patel
Rudrik Patel

Reputation: 696

getSupportActionBar().setTitle("Title")

Upvotes: 2

Ramesh sambu
Ramesh sambu

Reputation: 3539

Set ActionBar title based on your need

ActionBar ab = getActionBar();
ab.setTitle("My Title");

Upvotes: 0

tahsinRupam
tahsinRupam

Reputation: 6405

You can set default Toolbar title as following:

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

For fragment:

getActivity().setTitle("Your Title");

Upvotes: 11

Related Questions