Skip to content

Instantly share code, notes, and snippets.

@kernelhcy
Created August 7, 2013 05:09
Show Gist options
  • Save kernelhcy/6171369 to your computer and use it in GitHub Desktop.
Save kernelhcy/6171369 to your computer and use it in GitHub Desktop.
Android中软键盘的操作
//隐藏软键盘。
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
//进入activity不显示软键盘
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
或者在AndroidManifest.xml中设置android:windowSoftInputMode="adjustUnspecified|stateHidden"。
/**
* 收起软键盘并设置提示文字
*/
public void collapseSoftInputMethod()
{
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(inputText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
}
/**
* 显示软键盘并设置提示文字
*/
public void showSoftInputMethod(CommentItem item)
{
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(inputText, InputMethodManager.SHOW_IMPLICIT);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment