I have an app build with Fragment
s. The problem is the Activity uses the Fragment class name for its title instead of the title I set. Some parts of the code that can be useful:
MainActivity.kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
topAppBar = binding.topAppBar
setSupportActionBar(topAppBar)
val navHostController = supportFragmentManager.findFragmentById(R.id.detailFragment)
val navController = navHostController?.findNavController()
if (navController != null) {
NavigationUI.setupActionBarWithNavController(this, navController)
}
}
}
DetailFragment.kt
class DetailFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
...
// Also tried in onCreateView and onCreateOptionsMenu
requireNotNull(this.activity).title = getString(R.string.app_name)
...
}
}
Any ideas?