Infinito Nirone 7

白羽の矢を刺すスタイル

自動でバリデーションを実行し、警告を表示できる EditText

特定の長さ以上になったら文字や背景色を赤くする、というような警告表示スタイルを使う機会が何度かあったので、ライブラリとして公開しました。

バリデーションの結果を EditText のスタイルに反映させるためのコンポーネントです。

https://github.com/KeithYokoma/AutoValidationEditText

指定できる条件は、今のところ文字列長だけ。今後はパターンマッチングも実装したい。 あるいは、条件をプラグインみたいに自分で追加できるとかやってみたい。

使い方は以下のとおり。

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:sample="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <jp.yokomark.widget.edittext.validation.AutoValidationEditText
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        sample:minLengthThreshold="5"
        sample:maxLengthThreshold="10"
        sample:alertType="textColor"
        sample:alertColor="#EDA098"
        sample:normalColor="#000000"/>
</RelativeLayout>

最低限必要な長さと、長さの上限を設定できます。

警告の表示の方法は、文字色を変えるか、背景色を変えるか、あるいは ErrorTip を使うかのいずれか。
表示方法に応じて設定するプロパティも変わります。文字色の場合は、その色を警告時と通常時の2つを設定。

Maven Repository もおいてあるので、そこからお使いください。