1.不实时显示已经写入字体

        etEvaluateContent.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.toString().trim().length() > maxLength) {                    etEvaluateContent.setText(s.toString().substring(0, maxLength));                    etEvaluateContent.setSelection(maxLength);                    ToastUtil.showToastWithImg("您最多能输入200个字", R.mipmap.toast_error);                }            }            @Override            public void afterTextChanged(Editable s) {            }        });

2.实时显示已经写入字体个数

etSuggestContent.addTextChangedListener(new TextWatcher() {            CharSequence input;            @Override            public void beforeTextChanged(CharSequence s, int start, int count, int after) {                input = s;            }            @Override            public void onTextChanged(CharSequence s, int start, int before, int count) {                tvMaxCount.setText(String.format("%d/200", input.length()));                if (input.length() > 199) {                    ToastUtil.showToastWithImg("您最多能输入200个字", R.mipmap.toast_error);                }            }            @Override            public void afterTextChanged(Editable s) {            }        });

注意:以上两种类型方案均需要在xml文件中设置最大字数属性(maxLength)。

 "@+id/et_suggest_content"        style="@style/text_normal_light"        android:layout_width="0dp"        android:layout_height="141dp"        android:layout_marginTop="@dimen/dp_10"        android:background="@color/white"        android:gravity="top"        android:hint="您可以在这里给我们建议帮助我们做的更好"        android:maxLength="200"        android:paddingBottom="@dimen/dp_27"        android:paddingLeft="@dimen/app_margin"        android:paddingRight="@dimen/app_margin"        android:paddingTop="@dimen/dp_10"        android:textColorHint="@color/hint"        app:layout_constraintLeft_toLeftOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constraintTop_toTopOf="parent"/>

更多相关文章

  1. Android TextView字体设置
  2. Android实时采集视频,并在PC上显示出采集到的视频的程序
  3. CSS字体随键盘弹出而改变
  4. Android Studio 实时显示布局文件Preview窗口
  5. textview设置字体以及引入新字体
  6. 使用ThinDownloadManager下载apk以及notification实时展示进度和
  7. Android 录音获取麦克风实时音量
  8. Android - Android Studio修改字体(font)大小(size)
  9. android studio 中文乱码,字体优化解决之道

随机推荐

  1. android绘图小结
  2. Android studio 下的aidl编程实现Android
  3. android字体工作原理
  4. android 反编译(dex 和 odex),非脑残转帖,绝
  5. 修改默认配置文件.android.gradle.androi
  6. HTML5开发岗位猛增44%,iOS增速不及Android
  7. Android异步2:深入详解 Handler+Looper+Me
  8. Android图形框架简介
  9. Android(安卓)应用程序安装方式 的详细调
  10. Android(安卓)Handler机制详解