Android中的谷歌输入法
我目前正在开发一个Android应用程序,可以通过软键盘接收用户输入。但是当我的键盘出现时出现了一些问题,当我使用下面的代码时,只有英文键盘:Android中的谷歌输入法,android,libgdx,ime,Android,Libgdx,Ime,我目前正在开发一个Android应用程序,可以通过软键盘接收用户输入。但是当我的键盘出现时出现了一些问题,当我使用下面的代码时,只有英文键盘: ((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); 谷歌输入法显示没有我的默
((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
谷歌输入法显示没有我的默认语言(这意味着我无法更改为其他语言,因为没有可选择的选项卡),但我搜索整篇文章,似乎无法通过代码更改输入法语言
我使用LIBGDX,它的ui元素(TextField)和Android的direclty都不能用我的默认语言(中文)显示谷歌输入法。但如果我使用系统输入法,它可以按预期工作
为了解决其他问题,我可以在其他应用程序中使用GoogleIME而没有任何问题,我还发布了我用来调用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();
}
}
编辑:
找到了相关的,根据报告,LIBGDX为英语开发者做了特定的配置,如果你是其他语言开发者,你不应该使用TextField UI直接调用IMM,只需使用下面的代码和标签UI,一切都会好的
label.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.input.getTextInput(new Input.TextInputListener() {
@Override
public void input(String text) {
label.setText(text);
Debugger.LogInConsole(text);
}
@Override
public void canceled() {
}
},"","","");
}
});
浪费大量时间阅读源代码,希望这能帮助其他人
label.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.input.getTextInput(new Input.TextInputListener() {
@Override
public void input(String text) {
label.setText(text);
Debugger.LogInConsole(text);
}
@Override
public void canceled() {
}
},"","","");
}
});