2016-02-16 9 views
20

में फ़्लोटिंग लेबल संकेत टेक्स्ट को अक्षम/निकालें यह काउंटर-अंतर्ज्ञानी प्रतीत हो सकता है लेकिन TextInputLayout में फ़्लोटिंग लेबल संकेत को अक्षम या निकालने का कोई तरीका है? TextInputLayout काउंटर के लिए EditText के बजाय TextInputLayout का उपयोग करना चाहता हूं।TextInputLayout XML

<android.support.design.widget.TextInputLayout 
      android:id="@+id/textContainer" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scrollbars="vertical" 
      app:counterEnabled="true" 
      app:counterMaxLength="100"> 

      <EditText 
       android:id="@+id/myEditText" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="top|left" 
       android:inputType="textMultiLine|textCapSentences" 
       android:maxLength="100" 
       android:scrollbars="vertical" 
       android:hint="This is my cool hint"/> 

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

बेस्ट विचार प्रोग्राम के आप देने के लिए संकेत और textChange घटना समय editbox कि विचार आप मदद कर सकते हैं –

+0

समस्या संकेत रंग है में अशक्त संकेत के बारे में बताएं है। कुछ टाइप करते समय यह सफेद हो जाता है। कृपया संकेत रंग बदलें या पृष्ठभूमि रंग बदलें। टाइप करते समय आपको संकेत दिखाई देगा। –

उत्तर

50

समर्थन लाइब्रेरी के संस्करण 23.2.0 आप

setHintEnabled(false) 

कॉल कर सकते हैं शुरू या इस तरह के रूप में अपने TextInputLayout एक्सएमएल में डालने:

app:hintEnabled="false" 

हालांकि नाम हो सकता है बनाता है आपको लगता है यह सभी संकेतों को हटा देता है, यह सिर्फ तैरने वाला एक हटा देता है।

संबंधित डॉक्स और मुद्दा: http://developer.android.com/reference/android/support/design/widget/TextInputLayout.html#setHintEnabled(boolean)

https://code.google.com/p/android/issues/detail?id=181590

0

मुझे लगता है कि यह तुम्हारी मदद करेगा:

textContainer.setHintAnimationEnabled(false); 
+0

मेरे दोस्त को काम नहीं करता है। मैंने कोड में और एक्सएमएल 'ऐप के माध्यम से कोशिश की: hintAnimationEnabled =" false "' और न ही काम किया। मुझे लगता है कि यह सिर्फ उस लेबल की एनीमेशन को अक्षम करता है। – Micro

+0

तो, आप संकेत टेक्स्ट को हटाना चाहते हैं, है ना? – Darshak

+0

मैं चाहता हूं कि संकेत टेक्स्ट 'एडिटटेक्स्ट' के अंदर दिखाई दे। फिर जब आप 'एडिटटेक्स्ट' पर क्लिक करते हैं, तो मैं फ़्लोटिंग लेबल पर जाने के बजाय संकेत टेक्स्ट गायब होना चाहता हूं। नियमित 'एडिटटेक्स्ट' की तरह ही यह करता है। – Micro

0

अद्यतन v23 करने के लिए डिजाइन पुस्तकालय और TextInputLayout

+0

यह सिर्फ वास्तविक एनीमेशन को अक्षम करता है, और कुछ नहीं करता ... –

21

वहाँ में app:hintAnimationEnabled="false" जोड़ने

यहाँ मैं अब तक किया है इसे प्राप्त करने के तीन तरीके हो सकते हैं:

TextInputLayout पर _ वर्ण पर सेट करें, और android:hint="This is my cool hint"EditText पर सेट रखें।

<android.support.design.widget.TextInputLayout 
    .... 
    .... 
    android:hint=" ">  <<---------- 

    <EditText 
     .... 
     .... 
     android:hint="This is my cool hint"/> <<---------- 

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

यह काम करता है क्योंकि TextInputLayoutEditText's संकेत उपयोग करने से पहले निम्नलिखित की जांच करता है:

// If we do not have a valid hint, try and retrieve it from the EditText 
if (TextUtils.isEmpty(mHint)) { 
    setHint(mEditText.getHint()); 
    // Clear the EditText's hint as we will display it ourselves 
    mEditText.setHint(null); 
} 

android:hint=" " की स्थापना करके, if (TextUtils.isEmpty(mHint))false को मूल्यांकन करती है और EditText इसके संकेत बरकरार रखती है।

<your.package.name.CTextInputLayout 
    .... 
    .... >  <<---------- 

    <EditText 
     .... 
     .... 
     android:hint="This is my cool hint"/> <<---------- 

</your.package.name.CTextInputLayout> 

:

public class CTextInputLayout extends TextInputLayout { 

    public CTextInputLayout(Context context) { 
     this(context, null); 
    } 

    public CTextInputLayout(Context context, AttributeSet attrs) { 
     this(context, attrs, 0); 
    } 

    public CTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

    @Override 
    public void addView(View child, int index, ViewGroup.LayoutParams params) { 
     if (child instanceof EditText) { 
      // cache the actual hint 
      CharSequence hint = ((EditText)child).getHint(); 
      // remove the hint for now - we don't want TextInputLayout to see it 
      ((EditText)child).setHint(null); 
      // let `TextInputLayout` do its thing 
      super.addView(child, index, params); 
      // finally, set the hint back 
      ((EditText)child).setHint(hint); 
     } else { 
      // Carry on adding the View... 
      super.addView(child, index, params); 
     } 
    } 
} 

फिर डिजाइन समर्थन पुस्तकालय से एक के बजाय अपने कस्टम CTextInoutLayout का उपयोग करें:

दूसरा विकल्प TextInputLayout उपवर्ग और उसके addView(View child, int index, ViewGroup.LayoutParams params) विधि ओवरराइड करने के लिए किया जाएगा 3 तीसरा, और शायद सबसे सीधा-आगे तरीका निम्न कॉल करना होगा:

// remove hint from `TextInputLayout` 
((TextInputLayout)findViewById(R.id.textContainer)).setHint(null); 
// set the hint back on the `EditText` 
// The passed `String` could also be a string resource 
((EditText)findViewById(R.id.myEditText)).setHint("This is my cool hinttt."); 
संबंधित मुद्दे