現在、ソフトキーボードによるユーザー入力を受け取ることができるAndroidアプリケーションを開発しています。それは私が他の言語に変更することができなかったこと、私のデフォルト言語(なしAndroidのGoogle IME
((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
とGoogle IME表示:しかし、私は以下のコードを使用する場合にのみ、英語キーボードがあり、私のキーボードが現れ、いくつかの問題があります選択するタブがないため)が、記事全体を検索すると、コードでIME言語を変更する方法がないようです。
私はLIBGDXを使用していますが、そのUI要素(TextField)も、Androidからdirecltyを呼び出すと、既定の言語(中国語)のGoogle IMEが表示されません。しかし、システムIMEを使用すると、期待どおりに動作する可能性があります。
明らかに他の問題のために、私は他のアプリでGoogle IMEを問題なく使用することができました。また、InputMethodManagerを呼び出すために使用したコードも投稿します。
package my.package;
import android.app.Service;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Handler;
import android.os.LocaleList;
import android.os.Looper;
import android.text.InputType;
import android.util.DisplayMetrics;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import android.widget.EditText;
import java.util.Locale;
import my.package.Debugger;
public final class AndroidKeyboardAdapter implements KeyboardAdapter{
InputMethodManager imm;
Context context;
EditText text;
public AndroidKeyboardAdapter(Context context) {
this.context = context;
imm = (InputMethodManager)context.getSystemService(Service.INPUT_METHOD_SERVICE);
}
public void showKeyboard() {
text = new EditText(context);
Locale locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
locale = context.getResources().getConfiguration().getLocales().get(0);
for(int i = 0; i < context.getResources().getConfiguration().getLocales().size();i++)
Debugger.LogInConsole(context.getResources().getConfiguration().getLocales().get(i).getCountry()); // show TW
} else{
//noinspection deprecation
locale = context.getResources().getConfiguration().locale;
Debugger.LogInConsole(locale.getCountry()); // not doing anything
}
Debugger.LogInConsole(Locale.getDefault().toString()); //show zh_tw
((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
public void hideKeyboard() {
imm.hideSoftInputFromWindow(text.getWindowToken(), 0);
}
public void onResume() {
text.requestFocus();
text.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
imm.showSoftInput(text, 0);
}
},200);
}
@Override
public String getText() {
return text.getText().toString();
}
}
はまた、IMM上のLIBGDXプロセスのソースコードを提供します。
@Override
public void setOnscreenKeyboardVisible (final boolean visible) {
handle.post(new Runnable() {
public void run() {
InputMethodManager manager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (visible) {
View view = ((AndroidGraphics)app.getGraphics()).getView();
view.setFocusable(true);
view.setFocusableInTouchMode(true);
manager.showSoftInput(((AndroidGraphics)app.getGraphics()).getView(), 0);
} else {
manager.hideSoftInputFromWindow(((AndroidGraphics)app.getGraphics()).getView().getWindowToken(), 0);
}
}
});
}