问题
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