24

द्वारा कवर किया गया है TextInputLayout में एक संपादन टेक्स्ट है जो बदले में उपयोगकर्ता से इनपुट प्राप्त करता है। TextInputLayout के साथ एंड्रॉइड डिज़ाइन सपोर्ट लाइब्रेरी के साथ पेश किया गया है, हम एडिटटेक्स्ट के बजाय एडिटटेक्स्ट को रखने वाले टेक्स्ट इनपुटपुटआउट में त्रुटि सेट करना चाहते हैं। यूआई लिखते समय केवल संपादन टेक्स्ट पर ध्यान केंद्रित किया जाएगा, न कि पूरे TextInputLayout जो त्रुटि को कवर करने वाले कीबोर्ड को ले जा सकता है। निम्नलिखित GIF नोटिस में उपयोगकर्ता को त्रुटि संदेश देखने के लिए पहले कीबोर्ड को हटाना होगा। कुंजीपटल का उपयोग करने के लिए आईएमई क्रियाओं को स्थापित करने के संयोजन में यह वास्तव में भ्रमित परिणामों की ओर जाता है।TextInputLayout में त्रुटि पाठ कीबोर्ड

example error

लेआउट एक्सएमएल कोड:

<android.support.design.widget.TextInputLayout 
    android:id="@+id/uid_text_input_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:errorEnabled="true" 
    android:layout_marginTop="8dp"> 

    <EditText 
     android:id="@+id/uid_edit_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:singleLine="true" 
     android:hint="Cardnumber" 
     android:imeOptions="actionDone"/> 

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

जावा कोड TextInputLayout करने के लिए त्रुटि की स्थापना:

uidTextInputLayout.setError("Incorrect cardnumber"); 

मुझे यकीन है कि त्रुटि संदेश उपयोगकर्ता अभिनय किए बिना देखा जा कर सकते हैं कैसे इसे देखने के लिए? क्या फोकस को स्थानांतरित करना संभव है?

+0

मुझे लगता है कि आपको एक बग रिपोर्ट [यहां] (https://code.google.com/p/android/issues/list) दर्ज करनी चाहिए। – natario

+1

बस अभी यह @mvai https://code.google.com/p/android/issues/detail?id=178153&thanks=178153&ts=1435245051 – Franzaine

+0

मैं आपके साथ सहमत हूं, अच्छी पकड़ (और शुभकामनाएं)। – natario

उत्तर

2

आपको सब कुछ ScrollView कंटेनर में रखना चाहिए ताकि उपयोगकर्ता कम से कम स्क्रॉल कर सकें और त्रुटि संदेश देख सकें। यही एकमात्र चीज है जो मेरे लिए काम करती है।

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 
     ... 
     other views 
     ... 
    </LinearLayout> 
</ScrollView> 
+1

हालांकि यह त्रुटि को संभव बनाता है, यह उपयोगकर्ता को इसके बारे में जानने और इसके लिए खोज किए बिना त्रुटि नहीं दिखाता है। यह एक यूएक्स दृष्टिकोण से एक आवश्यकता है और मैं इसे प्रतिबिंबित करने के लिए प्रश्न अपडेट कर दूंगा। आपके उत्तर के लिए धन्यवाद! – Franzaine

+0

मैं सहमत हूं लेकिन आपको कम से कम, त्रुटि संदेश देखने की संभावना उपयोगकर्ता को देना चाहिए। – netpork

-1

मैं सिर्फ यह पता लगाना है कि यदि आप त्रुटि पाठ के लिए निश्चित ऊंचाई, कीबोर्ड छुट्टी अंतरिक्ष में कंटेनर डाल

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="75dp" 
    android:layout_alignParentBottom="true"> 

    <android.support.design.widget.TextInputLayout 
    android:id="@+id/text_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    app:errorEnabled="true" 
    app:errorTextAppearance="@style/ErrorText"> 

    <EditText 
     android:id="@+id/editText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:imeOptions="actionGo" 
     android:inputType="textPersonName" 
     android:singleLine="true" /> 
    </android.support.design.widget.TextInputLayout> 
</FrameLayout> 
+1

फ्रेमलेआउट में "android: layout_alignParentBottom" विशेषता से मुझे लगता है कि आप क्या कर रहे हैं TextInputLauout के साथ "नीचे बार" जोड़ रहा है। जब कीबोर्ड द्वारा विंडो का आकार बदलता है तो यह पूरे फ्रेमलाइट को ऊपर ले जाता है। यह व्यवहार प्रश्न और समझाया गया मुद्दा से संबंधित नहीं है। – GuillermoMP

2

सुनिश्चित करें कि त्रुटि संदेश उपयोगकर्ता यह देखने के लिए अभिनय के बिना दिखाई दे रहा है, मैं TextInputLayout subclassed और इसे ScrollView के अंदर रखा। यह त्रुटि संदेश प्रकट करने के लिए आवश्यक होने पर मुझे नीचे स्क्रॉल करने देता है, हर अवसर पर त्रुटि संदेश सेट होता है। उस गतिविधि/खंड वर्ग में कोई बदलाव नहीं है जो इसका उपयोग करता है।

private inline fun <reified T> View.findParentOfType(): T? { 
    var p = parent 
    while (p != null && p !is T) p = p.parent 
    return p as T? 
} 

private fun ScrollView.scrollDownTo(descendant: View) { 
    howFarDownIs(descendant)?.let { smoothScrollBy(0, it) } 
} 

private fun NestedScrollView.scrollDownTo(descendant: View) { 
    howFarDownIs(descendant)?.let { smoothScrollBy(0, it) } 
} 

/** 
* Calculate how many pixels below the visible portion of [this] layout is the 
* bottom of [descendant]. 
* 
* In other words, how much you need to scroll down, to make [descendant]'s bottom 
* visible. 
*/ 
private fun FrameLayout.howFarDownIs(descendant: View): Int? { 
    return Rect().also { 
     // See https://stackoverflow.com/a/36740277/1916449 
     descendant.getDrawingRect(it) 
     offsetDescendantRectToMyCoords(descendant, it) 
    }.bottom.minus(height).minus(scrollY).takeIf { it > 0 } 
} 

मैं भी एक ही कक्षा में TextInputLayout.setError() leaves empty space after clearing the error तय:

enter image description here

/** 
* [TextInputLayout] subclass that handles error messages properly. 
*/ 
class SmartTextInputLayout @JvmOverloads constructor(
     context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 
) : TextInputLayout(context, attrs, defStyleAttr) { 

    private val scrollView by lazy { findParentOfType<ScrollView>() } 
    private val nestedScrollView by lazy { findParentOfType<NestedScrollView>() } 

    private fun scrollIfNeeded() { 
     // Wait a bit (like 10 frames) for other UI changes to happen 
     postDelayed({ 
      scrollView?.scrollDownTo(this) 
      nestedScrollView?.scrollDownTo(this) 
     }, 160) 
    } 

    override fun setError(error: CharSequence?) { 
     super.setError(error) 

     // work around https://stackoverflow.com/q/34242902/1916449 
     isErrorEnabled = error != null 

     // work around https://stackoverflow.com/q/31047449/1916449 
     scrollIfNeeded() 
    } 
} 

यहाँ सहायक तरीके हैं।

0

यह hacky है, लेकिन यहाँ क्या मैं इस को हल करने के लिए क्या किया है:

के बाद से इस मामले में मेरी TextInputLayout/EditText कॉम्बो एक RecyclerView के भीतर रहते हैं, मैं बस यह स्क्रॉल जब मैं त्रुटि सेट:

textInputLayout.setError(context.getString(R.string.error_message)) 
recyclerView.scrollBy(0, context.convertDpToPixel(24f)) 

यह काम करता है, लेकिन आदर्श रूप से आदर्श से कम है। यह अच्छा होगा अगर Google इसे ठीक करेगा, क्योंकि यह निश्चित रूप से एक बग है।

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