How to use android:inputType on an EditText to specify my custom IME?

岁酱吖の 提交于 2019-12-24 20:44:07

问题


My app includes a custom IME (that extends InputMethodService) and I would now like to specify this as the IME for all the EditTexts within my app.

Specifying an android:inputMethod for each EditText seems to be one old way of doing it, but android:inputMethod is now deprecated. The tooltip says to use android:inputType instead.

My existing code for one EditText is android:inputType="numberPassword", but when I change this to android:inputType=".MyCustomIME" (or android:inputType="com.example.MyCustomIME") I get this error in Android Studio:

Cannot resolve flag.

So what is the correct way to specify my IME (either for a single EditText or for the whole app) - and without losing my existing numberPassword value (as this determines my IME subtype that will be used)?

My IME is defined in my manifest as:

<service
    android:name=".MyCustomIME"
    android:label="@string/my_keyboard"
    android:permission="android.permission.BIND_INPUT_METHOD">
    <intent-filter>
        <action
            android:name="android.view.InputMethod" />
    </intent-filter>

    <meta-data
        android:name="android.view.im"
        android:resource="@xml/keyboard_method" />
</service>

(NB - Using android:name="com.example.MyCustomIME" in the above <service /> tag doesn't make any difference.)

来源:https://stackoverflow.com/questions/59400635/how-to-use-androidinputtype-on-an-edittext-to-specify-my-custom-ime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!