android edittext 设置字体颜色,Android应用开发之Android更改EditText下划线的颜色样式和动态获取输入的字数的代码教程...
本文将带你了解Android应用开发之Android更改EditText下划线的颜色样式和动态获取输入的字数的代码教程,希望本文对大家学Android有所帮助。
在styles.xml文件中声明自定义样式
通过android:theme属性将此样式应用于您的EditText
et_comment.addTextChangedListener(mTextWatcher); et_comment.setFocusable(true); et_comment.requestFocus();
TextWatcher mTextWatcher = new TextWatcher() { private CharSequence temp; private int editStart; private int editEnd; @Override public void beforeTextChanged(CharSequence s, int arg1, int arg2, int arg3) {temp = s; } @Override public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3) {if (s.length() <= 200) { word_remain.setText((200 - s.length()) + "/200");} } @Override public void afterTextChanged(Editable s) {editStart = et_comment.getSelectionStart();editEnd = et_comment.getSelectionEnd();if (temp.length() > 200) { ToastUtil.showToastShort("你输入的字数已经超过了限制!"); s.delete(editStart - 1, editEnd); int tempSelection = editStart; et_comment.setText(s); et_comment.setSelection(tempSelection);} } };
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Android频道!