我已经在android上开发了自定义键盘,我想添加一个按钮以启用我的键盘并将用户重定向到虚拟键盘页面或页面管理键盘,以便用户可以从那里打开我的键盘,例如类似于“ aitypekeyboard”中的内容,请参见屏幕截图。
答案 0 :(得分:1)
只需使用input method settings activity
打开Intent
。
Intent enableIntent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);
enableIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(enableIntent);
答案 1 :(得分:0)
有两种解决方案, 如果要完全自动化地执行此操作,则需要访问权限来控制移动键盘,如果可以访问,则将通过此代码自动执行此操作
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
否则,您可以通过此代码将他切换到设置无聊的个人资料
InputMethodManager imeManager =
(InputMethodManager)
getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
imeManager.showInputMethodPicker();
这是一些可以帮助您开发应用程序以处理键盘设置的功能:
**//get the old default keyboard in case you want to**
use it later, or keep it enabled
String oldDefaultKeyboard =
Settings.Secure.getString(resolver,
Setting.Secure.DEFAULT_INPUT_METHOD);
**//enable your keyboard without user permission**
Settings.Secure.putString(resolver,
Settings.Secure.ENABLED_INPUT_METHODS,
"com.my.keyboard/.full.path");
**//set your keyboard as the new default keyboard without user permission**
Settings.Secure.putString(resolver,
Settings.Secure.DEFAULT_INPUT_METHOD,
"com.my.keyboard/.full.path");
//通过此代码将键盘恢复为默认设置
@Override 公共无效onConfigurationChanged(Configuration newConfig){
int currentKeyboard = 0;
boolean isShifted = kv.isShifted();
for (int i = 0; i < keyboard.length; i++) {
if(kv.getKeyboard().equals(keyboard[i])){
currentKeyboard = i;
break;
}
}
super.onConfigurationChanged(newConfig);
initializeKeyboardArray();
setKeyboard(keyboard[currentKeyboard]);
kv.setShifted(isShifted);
}
private void initializeKeyboardArray(){
keyboard = new Keyboard[7];
keyboard[ARABIC] = arabic;
keyboard[ARABIC_SHIFT] = arabicShift;
keyboard[ARABIC_SYMBOLS] = arabicSymbols;
keyboard[ARABIC_SYMBOLS_SHIFT] = arabicSymbolsShift;
keyboard[QWERTY] = qwerty;
keyboard[QWERTY_SYMBOLS] = qwertySymbols;
keyboard[QWERTY_SYMBOLS_SHIFT] = qwertySymbolsShift;
}
答案 2 :(得分:0)
Intent enableIntent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);
enableIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(enableIntent);