亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

TextInputLayout輸入框控件的懸浮標(biāo)簽

 更新時(shí)間:2017年12月04日 10:38:06   作者:ZhengJiaoCsdn  
這篇文章主要為大家詳細(xì)介紹了TextInputLayout輸入框控件的懸浮標(biāo)簽,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了TextInputLayout輸入框懸浮標(biāo)簽的具體代碼,供大家參考,具體內(nèi)容如下

TextInputLayout也是5.0以后的效果,想要使用同樣需要在build中配置:

dependencies { 
 compile 'com.android.support:design:23.3.0' 
} 

TextInputLayout可以用來顯示一個(gè)提示錯(cuò)誤信息,把Hint放到EditText左上方等效果的一個(gè)布局;
如果項(xiàng)目中有這類的需求,使用TextInputLayout實(shí)現(xiàn)起來非常方便;
使用方法也比較簡單,直接用TextInputLayout包裹EditText即可:

<android.support.design.widget.TextInputLayout 
 android:id="@+id/til_user" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="20dp" 
 android:layout_marginLeft="20dp" 
 android:layout_marginRight="20dp"> 
 <EditText 
  android:id="@+id/et_user" 
  android:layout_width="match_parent" 
  android:layout_height="wrap_content" 
  android:hint="請(qǐng)輸入用戶名"/> 
 </android.support.design.widget.TextInputLayout> 

但是默認(rèn)情況下,當(dāng)你輸入文本的時(shí)候TextInputLayout只會(huì)將Hint移動(dòng)到左上方,不會(huì)有錯(cuò)誤提示,錯(cuò)誤提示需要我們手動(dòng)設(shè)置:

etUser= (EditText) findViewById(R.id.et_user); 
 tilUser= (TextInputLayout) findViewById(R.id.til_user); 
 
 //添加文本變化監(jiān)聽 
 etUser.addTextChangedListener(new TextWatcher() { 
  @Override 
  //輸入文本之前調(diào)用 
  public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
  } 
 
  @Override 
  //正在輸入的時(shí)候調(diào)用 
  public void onTextChanged(CharSequence s, int start, int before, int count) { 
  if(s.length()>6){ 
   //打開TextInputLayout異常提示 
   tilUser.setErrorEnabled(true); 
   //設(shè)置TextInputLayout異常提示信息 
   tilUser.setError("賬號(hào)最大長度為6"); 
  }else { 
   //關(guān)閉TextInputLayout異常提示 
   tilUser.setErrorEnabled(false); 
  } 
  } 
 
  @Override 
  //輸入以后調(diào)用 
  public void afterTextChanged(Editable s) { 
  } 
 }); 

點(diǎn)擊打開鏈接免費(fèi)下載源碼

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論