Set toolbar title
In kotlin
(activity as? AppCompatActivity)?.supportActionBar?.title = "title"
Edit:
Added null safe operator ?
to avoid NullPointer
in case ActionBar not available
Change it to
((AppCompatActivity)getActivity()).getSupportActionBar().setTitle("Home");
You needed to tell the activity it is an AppCompatActivity
.
Then you use getActivity()
to get the main activity since you are in a fragment.
Then just set the title as usual.