结构
1  | public final class InputMethodManager{  | 
类概述
整个输入法框架(IMF)结构的核心API,应用程序之间进行调度和当前输入法交互。你可以用Context.getSystemService() 取得这一接口的实例。
架构总述
输入法框架(IMF)共有三个主要部分:
- 输入法管理器,管理各部分的交互。它是一个客户端API,存在于各个应用程序的context中,用来沟通管理所有进程间交互的全局系统服务。
 - 输入法(IME) ,实现一个允许用户生成文本的独立交互模块。系统绑定一个当前的输入法。使其创建和生成,决定输入法何时隐藏或者显示它的UI。同一时间只能有一个IME运行。
 - 客户应用程序,通过输入法管理器控制输入焦点和IME的状态。一次只能有一个客户端使用IME。
 
常量
第一组:
1  | // hideSoftInputFromWindow(IBinder, int)中的标志,表示如果用户未显式地显示软键盘窗口,则隐藏窗口。  | 
第二组:
1  | // showSoftInput(View, int, ResultReceiver)和hideSoftInputFromWindow(IBinder, int, ResultReceiver)中ResultReceiver结果代码标志:软键盘窗口从隐藏切换到显示时的状态。  | 
第三组:
1  | // showSoftInput(View, int, ResultReceiver)和hideSoftInputFromWindow(IBinder, int, ResultReceiver)中ResultReceiver结果代码标志:软键盘窗口不变保持显示时的状态。  | 
第四组:
1  | // showSoftInput(View, int)标志,表示隐式显示输入窗口,非用户直接要求。窗口可能不显示。  | 
方法
1  | public void displayCompletions(View view, CompletionInfo[] completions)  | 
1  | public InputMethodSubtype getCurrentInputMethodSubtype ()  | 
1  | public List<InputMethodInfo> getEnabledInputMethodList ()  | 
1  | public List<InputMethodInfo> getInputMethodList ()  | 
1  | public void hideSoftInputFromInputMethod (IBinder token, int flags)  | 
1  | public boolean hideSoftInputFromWindow (IBinder windowToken, int flags)  | 
1  | public boolean hideSoftInputFromWindow (IBinder windowToken, int flags, ResultReceiver resultReceiver)  | 
1  | public void hideStatusIcon (IBinder imeToken)  | 
1  | public boolean isAcceptingText ()  | 
1  | public void restartInput (View view)  | 
1  | public void sendAppPrivateCommand (View view, String action, Bundle data)  | 
1  | public void setInputMethod (IBinder token, String id)  | 
1  | public void setInputMethodAndSubtype (IBinder token, String id, InputMethodSubtype subtype)  | 
1  | public void showInputMethodPicker ()  | 
1  | public void showStatusIcon (IBinder imeToken, String packageName, int iconId)  | 
1  | public void toggleSoftInput (int showFlags, int hideFlags)  | 
1  | public void toggleSoftInputFromWindow (IBinder windowToken, int showFlags, int hideFlags)  | 
1  | public void updateCursor (View view, int left, int top, int right, int bottom)  | 
1  | public void updateExtractedText (View view, int token, ExtractedText text)  | 
1  | public void updateSelection (View view, int selStart, int selEnd, int candidatesStart, int candidatesEnd)  | 
1  | public boolean showSoftInput (View view, int flags, ResultReceiver resultReceiver)  | 
1  | public boolean showSoftInput (View view, int flags)  | 
1  | public void showSoftInputFromInputMethod (IBinder token, int flags)  | 
常用法
调用显示系统默认的输入法
方法一:
1  | InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  | 
方法二:
1  | InputMethodManager imm=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  | 
调用隐藏系统默认的输入法
1  | InputMethodManager imm=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  | 
获取输入法的开关状态
1  | InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  | 
不自动弹出键盘
带有EditText控件的在第一次显示的时候会自动获得focus,并弹出键盘,如果不想自动弹出键盘,有两种方法:
法一:
在mainfest文件中把对应的activity设置
android:windowSoftInputMode="stateHidden" 或者android:windowSoftInputMode="stateUnchanged"。
法二:
可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus。注意TextView不要设置Visiable=gone,否则会失效。
1  | <TextView  | 
应用启动后自动打开输入法
1  | /**  | 
单机触发软键盘
1  | /**  |