首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Android上创建多个IME (输入法编辑器)子类型?

如何在Android上创建多个IME (输入法编辑器)子类型?
EN

Stack Overflow用户
提问于 2018-09-15 22:23:17
回答 1查看 2K关注 0票数 11

我试图创建多个IME子类型,但Android只识别一个。

method.xml

代码语言:javascript
复制
<?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中每个名称都有值。

代码语言:javascript
复制
<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方法包括:

代码语言:javascript
复制
@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,以防有帮助。

代码语言:javascript
复制
<?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>

EN

回答 1

Stack Overflow用户

发布于 2021-05-09 01:01:31

还可以通过检索以下设置"selected_input_method_subtype“获得系统编辑器的输入方法子类型ID (当前设置编辑器或当前设置为默认编辑器,但不确定)。例如,1891618174是Gboard的子类型ID。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52349371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档