我需要一个帮助,我想以编程方式从谷歌软键盘隐藏数字,并且只想在 CapsLock 上显示字母,正如您可以看到此链接 http://www.androidcentral.com/how-add-dedicated-number-row-google-keyboard ,它在键盘上方显示数字,我不想要。
我试过了:
edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()}); // for making capslock on
<EditText
android:id="@+id/firstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapCharacters"
android:maxLength="10"/>
但数字仍然显示,用户也可以输入数字,我不需要,我需要用户只能输入字母 A 到 Z
我找到了一个解决方案,用户无法输入数字,但不显示大写字母(软键盘上的大写字母打开)。
这是解决方案,现在对我有用:感谢大家的支持。
edittext.setFilters(new InputFilter[] {
new InputFilter() {
public CharSequence filter(CharSequence src, int start,
int end, Spanned dst, int dstart, int dend) {
if(src.equals("")){ // for backspace
return src;
}
if(src.toString().matches("[A-Z ]+")){
return src;
}
return "";
}
}
});
<EditText
android:id="@+id/firstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapCharacters"
android:maxLength="10"/>
最佳答案
第一种方法:-在您的 EditText 上设置 android:inputType="textCapSentences"
。
但这只有在您的设备键盘自动大写设置启用时才有效。
第二种方式:-可以使用InputFilters以编程方式
edittext.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
更新答案: 尝试将此行添加到您的 EditText 标记中。
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
希望这对你有用。
关于android - 如何以编程方式隐藏谷歌软键盘上显示的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42064596/