更改右侧图标错误的TextInputLayout样式

5
我想改变TextInputLayout中右侧错误图标(带有感叹号的图片)的样式,但我不知道该如何操作。
这个可行吗? TextInputLayout

你能提供你现在正在使用的代码吗?看起来你正在为EditText设置错误。 - Jude Osbert K
2个回答

2
使用 Material 组件库时,只需使用 app:errorIconDrawable 属性即可。
例如:
<com.google.android.material.textfield.TextInputLayout
    app:errorIconDrawable="@drawable/..."
    ../>

enter image description here


0

在你的Java类中,你可以像这样做:

// 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);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接