Change style of the right icon error TextInputLayout

ぐ巨炮叔叔 提交于 2021-02-18 15:10:45

问题


I want to change the style of the right icon error (the image with ! sign) in a TextInputLayout but I don't find how.

It is possible?.

TextInputLayout


回答1:


With the Material Component Library just use the app:errorIconDrawable attribute.

Something like:

<com.google.android.material.textfield.TextInputLayout
    app:errorIconDrawable="@drawable/..."
    ../>




回答2:


To do this in your Java class, you can do something like this:

// initialize your drawable object
Drawable myErrorDrawable = getResources().getDrawable(R.drawable.my_error_drawable);

// set the dimension/bounds
myErrorDrawable.setBounds(0, 0, myErrorDrawable.getIntrinsicWidth(), myErrorDrawable.getIntrinsicHeight());

// attach the drawable to your EditText.
editText.setError("An error occured", myErrorDrawable);


来源:https://stackoverflow.com/questions/37974299/change-style-of-the-right-icon-error-textinputlayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!