I want to have my CustomTextInputLayout
to have Widget.MaterialComponents.TextInputLayout.OutlinedBox
as default style without defining it anywhere in the XML.
I tried this
class CustomTextInputLayout @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : TextInputLayout(ContextThemeWrapper(context, R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox), attrs, defStyleAttr) {
}
and this
class CustomTextInputLayout @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : TextInputLayout(context, attrs, R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox)
but it's not working. I've tried the default XML way
<com.custom.CustomTextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
...>
<com.google.android.material.textfield.TextInputEditText
...
android:hint="Sample Hint" />
</com.custom.CustomTextInputLayout>
and it's working.
- What am I missing here?
- How can I set a default style for custom
TextInputLayout
without usingXML
?