这是我的编辑文本xml代码
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
android:theme="@style/TextLabel1">
<EditText
android:id="@+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textCursorDrawable="@drawable/color_cursor"/>
</android.support.design.widget.TextInputLayout>
我的文本编辑类代码
if (PassWordSignUp.length()<6) {
PassWordSignUp.setError("Your password is less than 6 characters!");
PassWordSignUp.requestFocus();
}
我也在寻找一个答案,我得到了。你可以设置你自己的drawable(有margin)来代替红色的感叹号图标。
如何让那个自定义的图标有margin.首先,你用你想要的图标创建一个新的Vector Asset。
Drawable -> new -> Vector Asset -> Choose your icon -> Next -> Finish(完成)
现在创建全新的drawable,它将访问矢量图标.另外,你现在将添加边缘。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="32dp" //Adding the margin
android:drawable="@drawable/the_name_of_your_vector_icon"/> //Accessing the vector icon
</layer-list>
你有你的XML资源。现在只需显示你新创建的(带边距)图标,而不是正常的图标。
Drawable customisedErrorIcon =
getResources().getDrawable(R.drawable.your_new_error_icon);
if (customisedErrorIcon != null) {
customisedErrorIcon.setBounds(0, 0,
customisedErrorIcon.getIntrinsicWidth(),
customisedErrorIcon.getIntrinsicHeight());
}
yourEditText.setError("Error message", customisedErrorIcon);
这就是你如何将自定义的drawable设置为错误图标。这就是结果。