I'm using code like
EditText.setError("Something went wrong");
to show an error on an EditText
. But only the exclamation mark icon is shown, not the text of the error. Clicking on it shows the error text.
How can I have the error text display automatically, without needing to touch the icon first?
答案 0 :(得分:3)
您可以将焦点设置为EditText,这样用户就不必点击它。
editText.requestFocus()
但是,这仍然只能一次显示一个错误。我相信这可能仍然是最好的方式,因为这是平台实现它的方式。
答案 1 :(得分:0)
// In you layout Xml
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:id="@+id/layFName"
android:textColorHint="@color/edittext_hintcolor"
app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et_name_registration"
android:inputType="textPersonName"
android:hint="Hint Text"
/>
</android.support.design.widget.TextInputLayout>
// In java
private TextInputLayout mLayFName;
mLayFName = (TextInputLayout) findViewById(R.id.layFName);
for set error
mInputLayoutView.setError(msg);
EditText.getBackground().setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_ATOP);}