android限制edittext最大行数的方法
2016-02-23 11:11
495 查看
getInputView().addTextChangedListener(new TextWatcher() { String currentText = ""; @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) { int lines = getInputView().getLineCount(); // 限制最大输入行数 if (lines > getInputView().getMaxLines()) { getInputView().setText(currentText); getInputView().setSelection(currentText.length()); } else if (lines <= getInputView().getMaxLines()) { currentText = s != null ? s.toString() : ""; } } });
xml文件中可以通过
android:lines="3" 或者 android:maxLines="3" 来限制
相关文章推荐
- Android学习笔记day4
- Android 通过JNI实现守护进程,使得Service服务不被杀死
- android shape的使用
- android 常见命令总结
- Java/Android常用工具类
- Android性能优化之Bitmap的内存优化
- Android NDK隐藏jni动态库的内部符号表
- Android 安全机制一:allowBackup安全风险描述
- android 应用完全退出
- Android.mk的用法和基础
- Android UI效果之绘图篇(三)
- win32 ios android 获取系统时间
- android特殊字符
- android 之MVP模式的入门
- Android事件驱动机制--选择事件
- Android性能优化之Bitmap的内存优化
- Android--向SD卡读写数据
- android 自定义具有反弹效果的ScrollView
- Android高级控件----AdapterView与Adapter
- android源码社区和相关资料