How to automatically display a foreign keyboard instead of default English keyboard on the type panel?

隐身守侯 提交于 2020-01-07 06:59:05

问题


I'm making a questions and answers game in a language other than English. The questions will be in Nepali (similar to indian) and user needs to type answers in the same script. When I run the app the English keyboard gets displayed and I've to switch to the Nepali keyboard before typing. But is there anyway that when user taps into the type panel, it automatically displays a Nepali Keyboard instead of English (as English Keyboard is the primary keyboard in every phone)?

Upon searching on the net I found something like this:

private void showInputMethodPicker() {
    InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE); 
    if (imeManager != null) {
        imeManager.showInputMethodPicker();
    } else {
        Toast.makeText(this, R.string.not_possible_im_picker, Toast.LENGTH_LONG).show();
    }
}

But I'm not sure what it does. Please Help!


回答1:


You can do, in your Activity that you want to have the keyboard in different language. If you have many activities that you want to have keyboards in another language.

    Resources res = context.getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    android.content.res.Configuration conf = res.getConfiguration();
    conf.locale = new Locale(language_code.toLowerCase());
    res.updateConfiguration(conf, dm);


来源:https://stackoverflow.com/questions/32299276/how-to-automatically-display-a-foreign-keyboard-instead-of-default-english-keybo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!