【发布时间】:2019-02-20 07:03:20
【问题描述】:
我正在尝试创建多个 IME 子类型,但 Android 只能识别一个。
方法.xml
<?xml version="1.0" encoding="utf-8"?>
<input-method
xmlns:android="http://schemas.android.com/apk/res/android"
android:supportsSwitchingToNextInputMethod="true"
android:settingsActivity="com.example.softkeyboard.Settings">
<subtype android:name="@string/display_name_english_keyboard_dynamic_ime"
android:imeSubtypeLocale="en_US"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="charDataFile=strokemaps_dynamic" />
<subtype android:name="@string/display_name_english_keyboard_ime"
android:imeSubtypeLocale="en_US"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="charDataFile=strokemaps" />
</input-method>
strings.xml 中有每个名称的值。
<resources>
<string name="app_name">KK1</string>
<string name="display_name_english_keyboard_ime">English</string>
<string name="display_name_english_keyboard_dynamic_ime">English Dynamic</string>
我的 InputMethodService.onStartInputView 方法包括:
@Override
public void onStartInputView(EditorInfo ei, boolean restarting) {
super.onStartInputView(ei, restarting);
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
List<InputMethodInfo> imil = imm.getEnabledInputMethodList();
for (InputMethodInfo imi: imil) {
Log.e("osiv", "input method info: "+imi.toString());
}
List<InputMethodSubtype> imsl = imm.getEnabledInputMethodSubtypeList(imil.get(0), true);
for (InputMethodSubtype ims: imsl) {
Log.e("osiv", "input method subtype: "+ims.toString());
}
并且列出的 InputMethodInfos 包括我的 IME,但子类型列表仅包括一个子类型。如果文件中只有一个子类型,则每个子类型都会起作用。
Android 8.0 设备的语言/键盘配置选项中没有子类型,只有 IME 本身,因此无法单独启用或禁用子类型。
是否需要其他配置项来告诉 Android 允许多个 IME 子类型?
上面的代码有明显的问题吗?
这是 AndroidManifest,以防万一。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.k.k.kk1">
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".KKInputMethodService"
android:permission="android.permission.BIND_INPUT_METHOD"
android:label="KK"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.view.InputMethod"/>
</intent-filter>
<meta-data
android:name="android.view.im"
android:resource="@xml/method"/>
</service>
</application>
【问题讨论】:
-
我怀疑原因是您的两个子类型具有相同的
imeSubtypeLocale。
标签: android keyboard android-softkeyboard android-8.0-oreo ime