MaterialEditText 一个灰常漂亮的强大EditText
2016-08-03 17:11
357 查看
非常强大 贴网址使用自己看吧
点击打开链接
下午用setOnKeyListener 监听按键输入,发现字母跟数字无法监听,估计这些都不是key吧。。。
于是乎转用TextWatcher 药到病除上代码:
//--新增 设置 EditText 范围检查
public ViewHolder setEditTextCheck(int viewID, Object object) {
final MaterialEditText editText = getView(viewID);
DeviceParameterBean deviceParameterBean = (DeviceParameterBean) object;
;
final int[] scope = deviceParameterBean.getScope();
if (deviceParameterBean != null) {
editText.setText(deviceParameterBean.getValue());
editText.setFloatingLabelText(deviceParameterBean.getName());
if (scope != null && scope.length == 2)
editText.setHelperText(String.format("请输入范围在[%s,%s]", scope[0], scope[1]));
}
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
try {
float tempValue = Float.parseFloat(editText.getText().toString());
if (scope != null && scope.length == 2) {
if (tempValue > scope[1] || tempValue < scope[0]) {
editText.setError(String.format("非法输入\n请输入范围在[%s,%s]", scope[0], scope[1]));
}
}
} catch (Exception e) {
if (scope != null && scope.length == 2)
editText.setError(String.format("非法输入\n请输入范围在[%s,%s]", scope[0], scope[1]));
}
}
});
return this;
}
点击打开链接
下午用setOnKeyListener 监听按键输入,发现字母跟数字无法监听,估计这些都不是key吧。。。
于是乎转用TextWatcher 药到病除上代码:
//--新增 设置 EditText 范围检查
public ViewHolder setEditTextCheck(int viewID, Object object) {
final MaterialEditText editText = getView(viewID);
DeviceParameterBean deviceParameterBean = (DeviceParameterBean) object;
;
final int[] scope = deviceParameterBean.getScope();
if (deviceParameterBean != null) {
editText.setText(deviceParameterBean.getValue());
editText.setFloatingLabelText(deviceParameterBean.getName());
if (scope != null && scope.length == 2)
editText.setHelperText(String.format("请输入范围在[%s,%s]", scope[0], scope[1]));
}
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
try {
float tempValue = Float.parseFloat(editText.getText().toString());
if (scope != null && scope.length == 2) {
if (tempValue > scope[1] || tempValue < scope[0]) {
editText.setError(String.format("非法输入\n请输入范围在[%s,%s]", scope[0], scope[1]));
}
}
} catch (Exception e) {
if (scope != null && scope.length == 2)
editText.setError(String.format("非法输入\n请输入范围在[%s,%s]", scope[0], scope[1]));
}
}
});
return this;
}
相关文章推荐
- 布局中上面一个子布局,中间一个listview,下面一个edittext,解决edittext点击后输入法遮盖布局的问题
- 【MaterialEditText】 Material Design 的 EditText
- 分享一个GitHub 上的控件:MaterialEditText 详解
- 一个EditText,实现无边框,无背景,输入提示图标高亮闪动。
- Android限定EditText的输入类型为数字或者英文(包括大小写),EditText,TextView只能输入两位小数
- Android开发每次都需要按一个退格键或者回车才能显示出我edittext控件里面的内容
- Android开发心得——点击EditText的时候,输入法把整体布局顶出了屏幕?这里提供一个我个人的解决办法
- 移除一个activity中的EditText的默认焦点
- Activity上只有一个EditText,隐藏软键盘不自动弹出
- Android: 让一个EditText失去焦点,setFocusableInTouchMode与setFocusable 效果不一样
- android EditText 默认情况下不获取焦点(不弹出输入法)+点击EditText时,不弹出键
- QT textEdit,lineedit删除光标前一个字符
- EditText在光标处加入或删除一个字符串
- <TextView android:text="密 码:" <EditText android:id="@+id/EditTextPwd"
- 安卓使用EditText进入一个新页面时自动获取焦点弹出输入法界面解决办法
- EditText 获取焦点时 输入法弹出 点击EditText以外的部分 输入法隐藏
- [android]How to implement an not editable scrollable EditText?(如何实现一个不可编辑的带滚动条的EditText?) .
- PopupWindow当中包含EditText时,editText获得焦点后软键盘不出现
- 如何在EditText中嵌入一个Button
- Android学习小Demo(11)一个显示行线的自定义EditText