gpt4 book ai didi

java - 以编程方式更改键盘输入语言

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:32:12 25 4
gpt4 key购买 nike

我正在开发一个应用程序,我需要允许用户根据要求或默认更改默认键盘中显示的输入键,例如,我可能会在开始时提示用户选择默认语言和之后,无论何时使用默认键盘,应用程序始终显示所选语言的键盘键,

I know this is possible, because in default keyboard app, when multiple input methods are selected, then long pressing the spacebar allows to change the input methods at runtime, if this is possible then my requirement is also possible...

我不想像下面这样提示输入默认键盘:

InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
imeManager.showInputMethodPicker();

我不想像这样一直更改语言环境并重新启动我的 Activity :

Resources res = getBaseContext().getResources();
// Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale("ru".toLowerCase());
res.updateConfiguration(conf, dm);
Log.i("inside onStart","after ever");
setContentView(R.layout.activity_main);

我只想以我想要的语言显示键盘输入。

最佳答案

只有出于安全原因,您的应用程序作为系统应用程序运行时,您才可以在不通知用户的情况下更改键盘。

您需要先在应用的 AndroidManifest.xml 中授予 Android 权限

"android.permission.WRITE_SECURE_SETTINGS"

然后你需要确定你的键盘的id。

-> 要知道 id,您需要将键盘默认设置为手动设置菜单,然后将此打印放在某处,

System.out.println(Settings.Secure.getString(getContentResolver(),Settings.Secure.DEFAULT_INPUT_METHOD));

一旦你打印 id 并且你知道你的键盘 id 你可以按照下面的方式做(我已将默认键盘更改为日语)

InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);

//imeManager.showInputMethodPicker(); //This is to see available keyboards.
imeManager.setInputMethod(null,"jp.co.omronsoft.openwnn/.OpenWnnJAJP");

尽情享受吧!

关于java - 以编程方式更改键盘输入语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36261166/

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