how can i replace the title in a toolbar with a custom layout View? And then i want to remove that view when i dismiss it. So i only want that view to be in the toolbar in one fragment.
i was trying this but it doesn't work:
activity.supportActionBar!!.setDisplayShowCustomEnabled(true);
activity.supportActionBar!!.setDisplayShowTitleEnabled(false);
activity.supportActionBar!!.customView = layoutInflater.inflate(R.layout.view_segmented_control, null, false)
That's the solution:
val activity = activity ?: return
val mainActivity = activity as MainActivity
mainActivity.supportActionBar?.setDisplayShowCustomEnabled(true)
mainActivity.supportActionBar?.setDisplayShowTitleEnabled(false)
mainActivity.supportActionBar?.customView = layoutInflater.inflate(R.layout.view_segmented_control, null, false)
segmentedControl = layoutInflater.inflate(R.layout.view_segmented_control, null, false)
segmentedControl.segmented_control.notifyConfigIsChanged()
val toolbar = mainActivity.findViewById<androidx.appcompat.widget.Toolbar>(R.id.toolbar)
toolbar.addView(segmentedControl, toolbar.childCount)