如何获得用户键盘语言 [英] how to get user keyboard language

查看:96
本文介绍了如何获得用户键盘语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用编辑文本的应用程序.我想知道在oncreate方法中或键盘输入类型更改时用户输入的语言是什么.有什么方法可以设置侦听器以获取更改?我找到的所有答案都是关于语言环境的,而不是关于输入语言的.我不想处理语言环境,语言环境在应用程序中没有作用,输入语言却可以. 我用了这些代码.

I am writing an application which is using a edit text .i want to know whats users input language in oncreate method or when keyboard input type changes. Is there any way to set a listener to get that change? All the answer i found were about locale and not about input language. I don't want to handle locale, locale has no effect in application, the input language does. i used this codes.

private void printInputLanguages() {

    List<InputMethodInfo> ims = imm.getEnabledInputMethodList();
    for (InputMethodInfo method : ims) {
        List<InputMethodSubtype> submethods = imm
                .getEnabledInputMethodSubtypeList(method, true);
        for (InputMethodSubtype submethod : submethods) {
            if (submethod.getMode().equals("keyboard")) {
                String currentLocale =

                submethod.getLocale();
                tv.setText(currentLocale);
                Log.i("sara", "Available input method locale: "
                        + currentLocale);
            }
        }
    }

}

和此代码,但没有一个完全有用.

and this codes but none of them wasnt help full.

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
    String localeString = ims.getLocale();
    Locale locale = new Locale(localeString);
    String currentLanguage = locale.getDisplayLanguage();

感谢您的帮助.

推荐答案

无法执行此操作.键盘的输入语言没有报告给操作系统-实际上,Android没有输入语言的概念.这是第三方键盘制造商提出的一个想法.因此,实际上键盘可以以任何语言键入,而操作系统完全不知道.

There is no way to do this. The input language of a keyboard is not reported to the OS- in fact Android doesn't have the concept of an input language. It was an idea created by 3rd party keyboard manufacturers. So really a keyboard can be typing in any language and the OS would have no idea.

这篇关于如何获得用户键盘语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆