我正在关注this guide以显示错误,并this doc来实现错误。它工作正常,但不是在EditText下面显示错误,而是让它们在警告图标上方浮动。
<style name="error" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/accent</item> <!--apply the color you wat here -->
<item name="android:textSize">12dp</item>
</style>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
app:errorEnabled="true"
app:errorTextAppearance="@style/error">
<android.support.design.widget.TextInputEditText
android:id="@+id/txtPhoneNumber"
android:textSize="24dp"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number" />
</android.support.design.widget.TextInputLayout>
txtPhoneNumber.setError("Invalid Format");
如何让错误显示在EditText下面?
答案 0 :(得分:1)
您应该在那里传递 TextInputLayout 对象。
<android.support.design.widget.TextInputLayout
android:id="@+id/txtLayout">
.........
</android.support.design.widget.TextInputLayout>
然后
txtLayoutOBJ.setError("Invalid Format");
答案 1 :(得分:1)
TextInputLayout til = (TextInputLayout)findViewById(R.id.text_input_layout)
til.setError("Your Error");