Android EditText大写字母数字键盘

时间:2020-03-25 19:26:07

标签: android android-edittext android-softkeyboard

我有一个EditText,它应该显示字母数字键盘(在键盘上可以看到字母和数字)。字母必须为大写。我应该为EditText设置哪些属性?我尝试过:

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textVisiblePassword"
    android:textAllCaps="true" />

这显示小写字母数字键盘。

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textCapCharacters"
    android:textAllCaps="true" />

这显示了大写键盘,但没有数字。

我需要这样的键盘: enter image description here

在默认布局上可见的数字和大写字母(无需打开CAPS,或者换句话说,默认情况下打开CAPS)。

3 个答案:

答案 0 :(得分:0)

尝试inputType = textVisiblePassword | textCapCharacters

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textVisiblePassword|textCapCharacters" />

答案 1 :(得分:0)

当您拥有android:inputType="textCapCharacters"时,您将拥有字母数字键盘,如这些图片所示:

enter image description here enter image description here

您可以在手机的设置中更改键盘样式。用户还可以设置键盘使其完全不可见。但是您可以制作自定义键盘。这个问题可能会帮助您:How can you make a custom keyboard in Android?

答案 2 :(得分:0)

您可以使用android:digits属性来限制其他文本

android:inputType="textCapCharacters"
android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "