2017-08-09 14 views
0

私はthis guideの後にエラーを表示し、それを実装するにはthis docです。それは正常に動作しますが、EditTextの下にエラーを表示するのではなく、警告アイコンで上に浮かんでいます。私はエラーがのEditTextの下に表示されるようにすることができますどのようsetErrorは、テキストをEditTextの代わりにフライアウトに表示します

enter image description here

enter image description here

enter image description here

<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"); 

答えて

1

TextInputLayoutオブジェクトを渡す必要があります。

<android.support.design.widget.TextInputLayout 
    android:id="@+id/txtLayout"> 
    .........  
</android.support.design.widget.TextInputLayout> 

その後

txtLayoutOBJ.setError("Invalid Format"); 
+1

ああ、私ははい、レイアウトを使用EDITTEXTない、クールな –

+0

@AlexeyStrakh必要があります。 'TextInputEditText'の代わりに' TextInputLayout'を使用してください –

1
TextInputLayout til = (TextInputLayout)findViewById(R.id.text_input_layout) 
til.setError("Your Error"); 
関連する問題