6

内部に EditText を含む TextInputLayout があります。

これは私のxmlです:

<android.support.design.widget.TextInputLayout
    android:id="@+id/textInputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="Enter Text" />

</android.support.design.widget.TextInputLayout>

私のJavaコード:

((TextInputLayout) findViewById(R.id.textInputLayout)).setError("ERROR");

setError("ERROR")を呼び出すと、ラベル (ヒント) の色と EditText の一番下の線の色が赤に変わり、エラーが表示されます。これは私が期待する動作です。

ここで、アクティビティを破棄する前にsetError(null)を呼び出さないとしましょう。ここで、同じアクティビティをもう一度開きます。ラベルの色がリセットされ、エラー メッセージが消えたように見えますが、アプリケーション内のすべての EditText フィールドの最終行が赤のままであることがわかります。これは常に再現できるとは限りませんが、試行を続ければ、最終的には取得できます。

5.1.1 の Nexus 4 を使用しています。

私は何か間違ったことをしていますか?

4

4 に答える 4

0

この問題は、com.android.support: ... ライブラリのバージョン 23.1.1 で解決されています。

于 2016-01-20T15:15:50.187 に答える
0

@リチャードが言ったように、それはバグです。 問題 190829: TextInputLayout setError により、アプリ内のすべての TIL に赤い下線が表示される

一定の状態をバックグラウンドに戻すソリューションを使用しました。setError() メソッドをオーバーライドする独自のカスタム クラスで TextInputLayout を拡張するだけです。

public class CustomTextInputLayout extends TextInputLayout {

    // Constructors...

    @Override
    public void setError(@Nullable CharSequence error) {

        super.setError(error);
        if ((getEditText() != null && getEditText().getBackground() != null) &&
            (Build.VERSION.SDK_INT == 22 || Build.VERSION.SDK_INT == 21)) {
            Drawable drawable = getEditText().getBackground().getConstantState().newDrawable();
            getEditText().setBackgroundDrawable(drawable);
        }
    }
}

そして、このクラスを EditText のラッピングに再利用しています。副作用はありませんでした。

于 2016-05-04T13:07:27.587 に答える