以编程方式更改android:digits
问题描述:
我在布局xml中有这个
I have this in the layout xml
android:digits="0123456789."
android:inputType="phone" />
我想要的是能够以编程方式更改它,并能够来回更改它. inputType部分可以配合使用
What I want is to be able to change it programatically and be able to change it back and forth. The inputType part is fine with
manual_ip.setInputType(InputType.TYPE_CLASS_TEXT);
或
manual_ip.setInputType(InputType.TYPE_CLASS_PHONE);
但是我对数字部分一无所知. 我需要将字符数限制为"0123456789".或根据复选框状态允许所有操作.
But I'm clueless with digits parts.. I need to limit the chars to "0123456789." or allow everything depending on a checkbox state.
答
添加
manual_ip.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
之后
manual_ip.setInputType(InputType.TYPE_CLASS_PHONE);
之后没有任何内容
manual_ip.setInputType(InputType.TYPE_CLASS_TEXT);
解决了我的问题!