首页 > 解决方案 > 当 EditText 获得焦点时显示一个风格化的键盘

问题描述

我正在开发一个使用键盘进行输入的游戏,但是当用户触摸输入字段时,我只想显示字母字符,没有数字或特殊符号。现在,当键盘打开时,应用程序如下所示:

在此处输入图像描述

当“键入一些字母”EditText 具有焦点时,如何用自定义键盘替换软键盘?

标签: androidandroid-softkeyboardandroid-custom-keyboard

解决方案


I ended up creating a layout of the keyboard I wanted and then I disabled the focus for the EditText:

<EditText
    android:id="@+id/typed_word"
    android:focusable="false"
    android:maxLength="10"
    android:inputType="text"
    android:textCursorDrawable="@drawable/custom_cursor"
    android:enabled="false"
    android:layout_below="@+id/word_list"
    android:digits="abcdefghijklmnopqrstuvwxyz"
    android:textSize="25sp"
    android:textColor="@color/colorPrimaryDark"
    android:layout_margin="10dp"
    android:hint="@string/type_hint"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

By disabling the focus, I was able to prevent the standard keyboard from being displayed.


推荐阅读