问题
I have two versions of an app I'm working on. The first version has a setError message that is set on an EditText UI line if the user tries to save data and the line is empty. The gradle dependencie uses version 24.0.0.
The message appears correctly as:
The second version of the app has the same setError code but the View looks distorted because it looks like the Edit Text line has been pushed down by the View so it no longer directly below the "Do" text and the red circular exclamation point is moved down to the left of the error message. This version uses the gradle dependencie version 24.2.0.
Any ideas on what could be causing this?
Per Mike M's comment below, I used the setError() on the TextInputLayout but that results in a completely different error message that shows up below the beginning of the EditText line that I'd rather not use:
Activity.java
...
public void onClickSave(View v) {
int stringTD = EditText.getText().toString().replace(" ", "").length();
if (stringTD == 0) {
EditText.requestFocus();
EditText.setError("Add a Do Item");
layout.xml
...
<android.support.design.widget.TextInputLayout
android:id="@+id/TD_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@color/colorFlLabelFinal"
app:hintTextAppearance="@style/FloatingLabel" >
<com.EditText
android:id="@+id/EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="2dp"
android:inputType="text|textCapSentences|textNoSuggestions"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textIsSelectable="true"
android:textColorHighlight="@color/colorPrimary"
android:paddingLeft="5dp"
android:paddingStart="5dp"
android:drawableStart="@drawable/24dp"
android:drawableLeft="@drawable/24dp"
android:drawablePadding="5dp"
android:maxLines="1"
android:maxLength="51"
android:imeOptions="actionNext|flagNoExtractUi"
android:nextFocusDown="@+id/DEditText" />
回答1:
According to this, if you use an EditText
inside a TextInputLayout
this kind of behavior occurs after version 24+. So the solution right now would be to use the EditText
alone.
Try it and see if it works.
来源:https://stackoverflow.com/questions/39360632/android-why-is-seterror-message-causing-view-distortion