添加字符计数
TextInputLayout 具有在其中定义的 EditText 的字符计数器 。
计数器将呈现在 EditText 下方。
只需使用 setCounterEnabled() 和 setCounterMaxLength 方法:
TextInputLayout til = (TextInputLayout) findViewById(R.id.username);
til.setCounterEnabled(true);
til.setCounterMaxLength(15);
或者 xml 中的 app:counterEnabled 和 app:counterMaxLength 属性。
<android.support.design.widget.TextInputLayout
app:counterEnabled="true"
app:counterMaxLength="15">
<EditText/>
</android.support.design.widget.TextInputLayout>