问题
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