import android.content.Context import android.util.AttributeSet import android.view.LayoutInflater import android.widget.EditText import android.widget.FrameLayout class MyCustomView : FrameLayout { val edit by lazy { findViewById(R.id.edit) as EditText } constructor(context: Context) : super(context) { init(context) } constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { init(context, attrs) } constructor(context: Context, attrs: AttributeSet, styleAttr: Int) : super(context, attrs, styleAttr) { init(context, attrs, styleAttr) } constructor(context: Context, attrs: AttributeSet, styleAttr: Int, styleRes: Int) : super(context, attrs, styleAttr, styleRes) { init(context, attrs, styleAttr, styleRes) } private fun init(context: Context, attrs: AttributeSet? = null, styleAttr: Int = 0, styleRes: Int = 0) { LayoutInflater.from(context).inflate(R.layout.view_my_custom_view, this, true) val array = context.theme.obtainStyledAttributes(attrs, R.styleable.TextField, styleAttr, styleRes) edit.hint = array.getText(R.styleable.TextField_android_hint) } }