Skip to content

Instantly share code, notes, and snippets.

@abidanBrito
Created December 28, 2021 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abidanBrito/6b4a25e2519a814ea231322bf02d03ac to your computer and use it in GitHub Desktop.
Save abidanBrito/6b4a25e2519a814ea231322bf02d03ac to your computer and use it in GitHub Desktop.
/////////////////////////////////////
// APPROACH #1
/////////////////////////////////////
// In the Fragment
val textView: TextView = activity!!.findViewById(R.id.custom_toolbar_title) as TextView
viewModel.fragmentName.observe(viewLifecycleOwner, {
textView.text = it
})
/////////////////////////////////////
// APPROACH #2
/////////////////////////////////////
// In the Activity
fun changeAppBarTitle(title: String) {
binding.customToolbarTitle.text = title
}
// In the Fragment
viewModel.fragmentName.value?.let {
(requireContext() as? MainActivity)?.changeAppBarTitle(it)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment