读书人

怎么通过代码控制软件键盘的显示与隐藏

发布时间: 2012-09-14 23:00:49 作者: rapoo

如何通过代码控制软件键盘的显示与隐藏(InputMethodManager 的使用)

我们使用EditText编辑文本的时候,通过会使用软件键盘的自动显示,这样可以方便用户的使用。那如何通过代码控制显示隐藏第一种方法:隐藏键盘//通过InputMethodManager 对象 管理软键盘显示隐藏InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);im.hideSoftInputFromWindow(etEditText.getWindowToken(), 0); //[backcolor=#f7f7f7][color=#666666]etEditText[/color][/backcolor] 是EditText对象显示键盘:可以通过下面的方面重新恢复显示调用的方法还是im.showSoftInput(etEditText,0);复制代码//boolean  showSoftInput(View view, int flags, ResultReceiver resultReceiver)boolean  showSoftInput(View view, int flags)void  showSoftInputFromInputMethod(IBinder token, int flags)第二种方法:隐藏键盘protected void hideKeyboard() {InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);        View currentFocus = getCurrentFocus();        if (currentFocus != null) {            IBinder localIBinder = getCurrentFocus().getWindowToken();            localInputMethodManager.hideSoftInputFromWindow(localIBinder, 0);        }    }

更多知识点的学习,可以到迹涯网 http://www.jiyanet.com




读书人网 >编程

热点推荐