gpt4 book ai didi

android - 如何在Android中获取用户设置默认键盘的ID

转载 作者:搜寻专家 更新时间:2023-11-01 09:48:49 25 4
gpt4 key购买 nike

我想在我的自定义键盘中创建一个按钮,按下该按钮会将键盘切换为默认用户键盘。我已经想出如何像这样设置输入键盘:

final String LATIN = "com.android.inputmethod.latin/.LatinIME";
final IBinder token = this.getWindow().getWindow().getAttributes().token;
imm.setInputMethod(token, LATIN);

在这种情况下,按下我想要实现的按钮会将键盘切换到默认的用户指定键盘(拉丁键盘)。

问题是在这个特定的例子中,字符串已经给出了。

如何找到默认用户指定键盘的 ID 字符串,以便我可以设置 InputMethod

最佳答案

您可以像下面的例子一样获取当前 Activity 键盘的 id:

String id = Settings.Secure.getString(
getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD)

如果您的软键盘当前正在用于输入,以上代码将返回您的键盘的 id。

但是,你可以这样做:当您的输入选择器按钮被点击时,您可以显示输入法列表,并让用户选择他喜欢的任何输入法:

InputMethodManager inputManager = (InputMethodManager) this.getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showInputMethodPicker();

以上代码将打开一个系统对话框,您可以在其中选择输入法。此外,您还可以获得输入法列表,如下面的代码所示:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList();

final int n = mInputMethodProperties.size();

for (int i = 0; i < n; i++) {
InputMethodInfo imi = mInputMethodProperties.get(i);
Log.d("TAG", "Input Method ID: "+ getApplicationContext().getPackageName(); }

关于android - 如何在Android中获取用户设置默认键盘的ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36732684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com