Set toolbar title dynamically using navigation-component

后端 未结 3 468
失恋的感觉
失恋的感觉 2020-12-17 02:09

I\'m trying to set the toolbar title dynamically, I don\'t know if it\'s possible or not.

Assume I have list of items every item I clicked it\'s open new fragment,

3条回答
  •  再見小時候
    2020-12-17 03:01

    you can add a method for updating the fragment title and call it in fragment onStart() method

    fun updateToolbarTitle(title: String) {
        supportActionBar?.title = title
    }
    

    and remove lable attribute from tag in your nav_graph.xml so it'll be like that

    
    

提交回复
热议问题