I'm new to android development in kotlin. I tried the following code to change the actionbar title from my fragment.It's not working.Please help
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity.actionBar?.title = "Example 1"
countBtn.setOnClickListener(this)
toastBtn.setOnClickListener(this)
randomBtn.setOnClickListener(this)
}
Run Code Online (Sandbox Code Playgroud)
MainActivity.kt code is as below
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
val actionBar = supportActionBar
actionBar?.title = getString(R.string.toolbar_title)
}
Run Code Online (Sandbox Code Playgroud)