androidtoolbarandroid-titlebar

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

Solution

  • You can set default Toolbar title as following:

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

    For fragment:

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