我试图创建多个IME子类型,但Android只识别一个。
method.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,但是子类型列表只包含一个子类型。如果每个子类型是文件中的唯一子类型,则每个子类型都会起作用。
Android8.0设备在其语言/键盘配置选项中不显示子类型,只显示IMEs本身,因此不能单独启用或禁用这些子类型。
是否还需要另一个配置项来告诉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>
发布于 2021-05-09 01:01:31
还可以通过检索以下设置"selected_input_method_subtype“获得系统编辑器的输入方法子类型ID (当前设置编辑器或当前设置为默认编辑器,但不确定)。例如,1891618174是Gboard的子类型ID。
https://stackoverflow.com/questions/52349371
复制相似问题