I've created custom actionbar titles for each fragment in my kotlin app. However sometimes it shows the fragmentname for a split second before showing the custom title.
This is the code I have in each fragment:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val binding = inflate<FragmentHomeBinding>(
inflater,
R.layout.fragment_home, container, false
)
////
//some binding
////
return binding.root
}
override fun onAttach(context: Context) {
super.onAttach(context)
(activity as AppCompatActivity).supportActionBar?.title = "Custom"
}
override fun onResume() {
super.onResume()
(activity as AppCompatActivity).supportActionBar?.title = "Custom"
}
Turned out I could just edit the label in navigation.xml to save a lot of trouble