调用setError()时,TextInputEditText边框消失

时间:2017-04-27 21:28:50

标签: android android-textinputlayout android-textinputedittext

我正在使用TextInputEditText的样式在字段周围放置边框,我正在使用TextInputLayout来设置错误消息。但是当调用setError ()时,边框会消失,并且只保留一个应该有一个字段的空间。

XML:

 <android.support.design.widget.TextInputLayout
                android:id="@+id/input"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp">

                 <android.support.design.widget.TextInputEditText
                    android:id="@+id/edittext"
                    android:layout_width="300dp"
                    android:layout_height="wrap_content"
                    style="@style/EditTextStyle"
                    android:textColor="@color/secondary_text"
                    android:paddingTop="@dimen/float_hint_margin"
                    android:textSize="15dp" />
            </android.support.design.widget.TextInputLayout>

EditTextStyle:

<style name="EditTextStyle">
        <item name="android:textColor">@color/secondary_text</item>
        <item name="android:background">@drawable/lgedittext</item>
        <item name="android:paddingTop">5dp</item>
        <item name="android:textSize">12dp</item>
        <item name="android:layout_marginTop">5dp</item>
        <item name="android:layout_height">30dp</item>
    </style>

lgedittext:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="@dimen/float_hint_margin">
        <shape>
            <solid android:color="@color/icons" />
            <stroke
                android:width="1dp"
                android:color="@color/divider" />
            <corners android:radius="8dp" />
        </shape>
    </item>
</layer-list>

活动

final TextInputEditText field = (TextInputEditText) dialog.findViewById(R.id.edittext);
final TextInputLayout input = (TextInputLayout) view.findViewById(R.id.input);
String text = field.getText().toString();
   if (!text.equals("")) {
      //do something
   } else {
      input.setError(getString(R.string.error_empty));
   }

0 个答案:

没有答案