2017-03-21 25 views
0

我試圖在編輯文本中顯示錯誤圖標,並在代碼下面嘗試,但它並未在所有編輯文本字段中顯示錯誤圖標。錯誤圖標未在所有EditText字段中顯示

txtEmailAddess.requestFocus(); 
txtEmailAddess.setError(result.getEmailAddressMessage()); 
txtPassword.requestFocus(); 
txtPassword.setError(result.getPasswordMessage()); 

在下面的截圖中,它僅顯示密碼字段中的錯誤圖標。但不在電子郵件地址字段。有可能在兩個領域都顯示紅色的圓形圖標嗎?

enter image description here

以XML 代碼

<android.support.design.widget.TextInputLayout 
    android:id="@+id/lblEmailAddress_login" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <EditText 
     android:id="@+id/txtEmailAddress" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/hint_email" 
     android:inputType="textEmailAddress" /> 
</android.support.design.widget.TextInputLayout> 

<android.support.design.widget.TextInputLayout 
    android:id="@+id/lblPassword_login" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/lblEmailAddress_login"> 
    <EditText 
     android:id="@+id/txtPassword" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="45dp" 
     android:hint="@string/hint_password" 
     android:inputType="textPassword" /> 
</android.support.design.widget.TextInputLayout> 
+0

請添加更多關於您調用的佈局和方法的代碼「..setError(..)」 –

+0

你可以用xml檢查嗎? – g7pro

+0

添加了代碼。請讓我知道如果你需要更多的細節。 – Pankaj

回答

1

使用TextInputLayout

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

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 
</android.support.design.widget.TextInputLayout> 

設置錯誤使用:

textInputLayout.setError("Error occurs"); 
0

的使用,如果別人對文本字段的每一個項目中的文本字段設置錯誤而不是請求焦點

+0

是否可以在所有編輯文本字段中顯示錯誤圖標? – Pankaj

+0

是的,因爲在我的答案你必須使用,如果其他條件爲每個文本字段 –

0

是的,在我的答案,你必須使用如果其他條件適用於每個文本字段

相關問題