国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

TextInputLayout輸入框控件的懸浮標簽

2019-12-12 01:33:02
字體:
來源:轉載
供稿:網友

本文實例為大家分享了TextInputLayout輸入框懸浮標簽的具體代碼,供大家參考,具體內容如下

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

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

TextInputLayout可以用來顯示一個提示錯誤信息,把Hint放到EditText左上方等效果的一個布局;
如果項目中有這類的需求,使用TextInputLayout實現起來非常方便;
使用方法也比較簡單,直接用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="請輸入用戶名"/>  </android.support.design.widget.TextInputLayout> 

但是默認情況下,當你輸入文本的時候TextInputLayout只會將Hint移動到左上方,不會有錯誤提示,錯誤提示需要我們手動設置:

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

點擊打開鏈接免費下載源碼

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 罗甸县| 裕民县| 拉萨市| 扶风县| 汕头市| 阳江市| 邵东县| 平邑县| 莱芜市| 深圳市| 堆龙德庆县| 阿鲁科尔沁旗| 平顺县| 涡阳县| 三门峡市| 徐水县| 娱乐| 文安县| 万源市| 兴国县| 滨州市| 巩留县| 建水县| 肃北| 邓州市| 平罗县| 乌兰察布市| 玉屏| 巴彦淖尔市| 耒阳市| 常德市| 简阳市| 桂阳县| 五家渠市| 河曲县| 西平县| 鄂温| 阿瓦提县| 神农架林区| 平乐县| 黔西|