2016-04-14 47 views
1

任何人都可以請求幫助解決edittext標籤浮動問題,根據我的要求提示文本應該在編輯框本身出現錯誤文本時顯示。眼下正在發生的事情,每當我顯示錯誤文本標籤也動,我不希望移動labeluntil,除非用戶開始輸入TextInput佈局顯示錯誤,但不會浮動標籤

的截圖,從谷歌設計的屏幕採取 http://www.google.com/design/spec/components/text-fields.html#text-fields-single-line-text-field enter image description here

+0

你可以分享你的xml文件? – Eenvincible

+0

添加了我的xml,請幫助我 – Bytecode

回答

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

     android:layout_marginLeft="@dimen/defaultLayoutPadding" 
     android:layout_marginRight="@dimen/defaultLayoutPadding" 
     android:layout_marginTop="@dimen/adv_top_padding"> 

     <android.support.v7.widget.AppCompatEditText 
      android:id="@+id/et_keyword_search" 
      style="@style/match_wrap.white_hint.no_focusable" 
      android:textColorHint="@color/color_white" 
      android:hint="@string/m_adv_keyskills" /> 


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

我檢查了代碼,這是默認的行爲FO TextInputLayout

final boolean hasText = mEditText != null && !TextUtils.isEmpty(mEditText.getText()); 
     final boolean isFocused = arrayContains(getDrawableState(), android.R.attr.state_focused); 
     final boolean isErrorShowing = !TextUtils.isEmpty(getError()); 

     if (mDefaultTextColor != null) { 
      mCollapsingTextHelper.setExpandedTextColor(mDefaultTextColor.getDefaultColor()); 
     } 

     if (mCounterOverflowed && mCounterView != null) { 
      mCollapsingTextHelper.setCollapsedTextColor(mCounterView.getCurrentTextColor()); 
     } else if (isErrorShowing && mErrorView != null) { 
      mCollapsingTextHelper.setCollapsedTextColor(mErrorView.getCurrentTextColor()); 
     } else if (isFocused && mFocusedTextColor != null) { 
      mCollapsingTextHelper.setCollapsedTextColor(mFocusedTextColor.getDefaultColor()); 
     } else if (mDefaultTextColor != null) { 
      mCollapsingTextHelper.setCollapsedTextColor(mDefaultTextColor.getDefaultColor()); 
     } 

     if (hasText || isFocused || isErrorShowing) { 
      // We should be showing the label so do so if it isn't already 
      collapseHint(animate); 
     } else { 
      // We should not be showing the label so hide it 


     expandHint(animate); 
    }