How to change the text on the action bar

前端 未结 18 786
春和景丽
春和景丽 2020-11-22 12:30

Currently it just displays the name of the application and I want it to display something custom and be different for each screen in my app.

For example: my home scr

18条回答
  •  抹茶落季
    2020-11-22 13:36

    For future developers that are using AndroidX and the navigation architectural component.

    Instead of setting the toolbar title using one of the solutions above, which can be very painful if you want to set it dynamically on a back stack change, you can set a placeholder for the title of the fragment in the navigation graph like the following:

    
        
    
    

    The placeholder value has to be provided using the FragmentDirections (via the action method).

    It is then replaced in the title and show like Hello World (when placeholder = "World").

提交回复
热议问题