[ad_1]
I have a toolbar in activity with a fragment container
<androidx.appcompat.widget.Toolbar
android:id="@+id/tlUsersActivity"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/white"
/>
I run these lines to control the backpressed button
setSupportActionBar(binding?.tlUsersActivity)
if (supportActionBar != null) {
when (intent.getStringExtra(MainActivityAdmin.FRAGMENT_TYPE)) {
"View Users" -> {
supportActionBar?.title = viewUsersText
}
"Edit Users" -> {
supportActionBar?.title = editUsersText
}
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
binding?.tlUsersActivity?.setNavigationOnClickListener { onBackPressed() }
I want to change this action from inside the fragment, I want to replace it with a function that replaces fragments.
I’ve tried this but it didn’t work
val actionBar = view?.findViewById<Toolbar>(R.id.tlUsersActivity)
actionBar?.setNavigationOnClickListener {
replaceFragment(FragmentEditUsers())
}
[ad_2]