publicvoidswitchInputMethod(ActivitymyActivity,EditTextinputText){
try
{
//Getlistofinputmethods
List<InputMethodInfo>InputMethods=((InputMethodManager)myActivity.getSystemService(Context.INPUT_METHOD_SERVICE)).getEnabledInputMethodList();

StringnameIME=InputMethods.get(3).getServiceName();
Log.i("DemoError","SWITCHINGTO:"+nameIME);
StringNewInputMethodName=InputMethods.get(3).getId();//Pickthefirstinputmethodtoswitchto
Log.i("DemoError","SWITCHINGTO:"+NewInputMethodName);
StringcurInputMethodId=Settings.Secure.getString(myActivity
.getContentResolver(),Settings.Secure.DEFAULT_INPUT_METHOD);
Log.i("DemoError","CURRENTIME:"+curInputMethodId);

//Solution1(X)
//switchInputMethodisamethodofandroid.inputmethodservice.InputMethodService
// switchInputMethod(NewInputMethodName);//Thisthrowsanerror

//Solution2(OK)
Settings.Secure.putString(myActivity.getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD,NewInputMethodName);

//Solution3(OK)
if(myActivity.checkCallingOrSelfPermission(
android.Manifest.permission.WRITE_SECURE_SETTINGS)
!=0){
//PERMISSION_GRANTED==0
Log.i("DemoError","myActivityrequirespermission"
+android.Manifest.permission.WRITE_SECURE_SETTINGS);
}

((InputMethodManager)myActivity.getSystemService(Context.INPUT_METHOD_SERVICE))
.setInputMethod(null,NewInputMethodName);


//ShowSoftInputKeyboard
((InputMethodManager)myActivity.getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(inputText,0);

}catch(Exceptione){
Log.i("DemoError",e.getMessage());
}
}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 在HTML / PHP联系表单上出现404/405错误(
  2. 急死我了!我以前用DREAMWEAVER编写的HTML
  3. HTML,CSS - 长表的行中断需要修复
  4. 样式通常以相同的组合出现:创建单个类还是
  5. 如何在Java Swing中的JPanel中呈现基本的
  6. 单个元素html上的多个类
  7. 如何使用jQuery在我的网站演示中自动填写
  8. JQuery基于元素的高度添加类
  9. HTML之表格篇——表格的嵌套
  10. 怎么动态设置html的canvas元素的尺寸?