Created
August 7, 2013 05:09
-
-
Save kernelhcy/6171369 to your computer and use it in GitHub Desktop.
Android中软键盘的操作
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//隐藏软键盘。 | |
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