Take the title control as an example
1. Create a class that inherits LinearLayout
2. Reference in activity.xml:
<com.firstlinetestapp.ui.view.TitleLayout android:layout_width="match_parent" android:layout_height="wrap_content" />
3. Edit the toolbar's control events:
class TitleLayout(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) { init { LayoutInflater.from(context).inflate(R.layout.title,this) title_back.onClick { val c = getContext() as Activity c?.finish() } title_edit.onClick { Toast.makeText(getContext(), "Clicked Edit button", Toast.LENGTH_SHORT).show() } } }