Skip to content Skip to sidebar Skip to footer

How Can I Set Style To Textinputlayout By Dynamically In Android?

I want to create TexInputLayout by dynamically. I can create TextInputLayout using following code block : TextInputLayout til = new TextInputLayout(this); EditText et = new EditTex

Solution 1:

The 2nd parameter of the ContextThemeWrapper is a theme overlay, not a style.

You can define in attrs.xml a custom attribute:

<attr name="customTextInputStyle"format="reference" />

then in your app theme:

<stylename="AppTheme"parent="Theme.MaterialComponents.*"><!-- ..... --><itemname="customTextInputStyle">@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox</item></style>

and finally:

TextInputLayouttil=newTextInputLayout(this,null,R.attr.customTextInputStyle);
    til.setHint("Label");
    TextInputEditTextet=newTextInputEditText(til.getContext());  //important: get the themed context from the TextInputLayout
    til.addView(et);
    buttonsLayout.addView(til);

enter image description here

Post a Comment for "How Can I Set Style To Textinputlayout By Dynamically In Android?"