TextInputLayout 的使用

来源:互联网 发布:Mac怎样设置快捷键 编辑:程序博客网 时间:2024/06/07 00:58
final TextInputLayout til= (TextInputLayout) findViewById(R.id.til);til.setHint("please input some words:");EditText et=til.getEditText();et.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) {    }    @Override    public void afterTextChanged(Editable s) {        if(s.length()>5){            til.setError("some Error");            til.setErrorEnabled(true);        }else {            til.setErrorEnabled(false);        }    }});

//xml
<android.support.design.widget.TextInputLayout    android:background="#0ff"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:id="@+id/til">    <android.support.design.widget.TextInputEditText        android:layout_width="match_parent"        android:layout_height="wrap_content"        /></android.support.design.widget.TextInputLayout>

0 0
原创粉丝点击