2016-09-04 9 views
5

missplaced मैं इसEditText त्रुटि आइकन और दिखाने पासवर्ड

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

      <EditText 
       android:id="@+id/password" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="@string/prompt_password" 
       android:imeActionId="@+id/login" 
       android:imeActionLabel="@string/action_sign_in_short" 
       android:imeOptions="actionUnspecified" 
       android:inputType="textPassword" 
       android:maxLines="1" 
       android:singleLine="true" /> 

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

यह काम कर रहा है की तरह पासवर्ड इनपुट के रूप में एक EditText है, लेकिन जब उसमें कोई त्रुटि है त्रुटि आइकन दो बार shwon और यह शो पासवर्ड आइकन के शीर्ष पर है।

error icon missplaced

मेरे सत्यापन त्रुटि को दिखाने के लिए कोड:

if (success) { 
    finish(); 
    startMainActivity(); 
} else { 
     mPasswordView.setError(getString(R.string.error_incorrect_password)); 
      mPasswordView.requestFocus(); 
} 
+0

अपना सत्यापन कोड पोस्ट करें। – user1688181

+0

मैंने अपनी पोस्ट –

+0

अपडेट की है "सफलता" चर क्या है और आपने इसे कहां से प्राप्त किया? – user1688181

उत्तर

16

EditText पर setError न करें, उसकी का उपयोग TextInputLayout के setError()

+0

यह काम करता है धन्यवाद, मैं सिर्फ एंड्रॉइड स्टूडियो से कोड टेम्पलेट का उपयोग लॉगिन एक्टिविटी –

+0

@Lyan Dwi Pangestu बनाने के लिए करता हूं: क्या आप उस कोड को पोस्ट कर सकते हैं जो आपको काम करने के लिए मिला है? मैं एक समान मुद्दे से निपट रहा हूं और यह देखकर सराहना करता हूं कि आपने अपनी समस्या का समाधान कैसे किया। – AJW

+0

@AJW के रूप में ianhanniballake ने कहा, EditText पर setError को कॉल न करें, TextInputLayout के setError का उपयोग करें, यह संपादन टेक्स्ट के नीचे त्रुटि संदेश दिखाएगा और अच्छा लगेगा –

-1

ऐसा लगता है कि यह एक बग के बाद है 24+ करने के लिए ग्रेडल निर्भरता अद्यतन। कृपया, this उत्तर देखें। मेरे पास मेरे सभी setError() इससे पहले ठीक काम कर रहे थे। इसके अलावा, आपको त्रुटि प्रदर्शित करने के लिए फोकस नहीं करना था।

संबंधित मुद्दे