Created
December 28, 2021 21:46
-
-
Save abidanBrito/6b4a25e2519a814ea231322bf02d03ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////// | |
// 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