android - 如何以编程方式隐藏谷歌软键盘上显示的数字

标签 android android-softkeyboard

我需要一个帮助,我想以编程方式从谷歌软键盘隐藏数字,并且只想在 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/

相关文章:

Android软键盘仅 float 特定布局

android - 键盘放置遮挡了下方的 View EditText 希望保持可见

android - 三星 Galaxy S4 流媒体视频播放方向问题

android - Renderscript - 获取相邻像素

java - 不幸的是 myandroidapps 已经停止

使用媒体查询时 Android 键盘无法打开

android - 如何在 Android 中以编程方式禁用表情符号

android - 房间数据库全动态查询

java - ListView 仅显示 ListView 第一个位置的最后一项

Android 问题 : EditText, KeyListener 和物理后退按钮