下面列出了android.view.inputmethod.InputMethodManager#showSoftInputFromInputMethod ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void hiddenKeybord() {
InputMethodManager manager = ((InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE));
if(manager==null){
return;
}
boolean isOpen = manager.isActive(); // 判断软键盘是否打开
if (isOpen && manager != null) {
manager.hideSoftInputFromWindow(mEditText.getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
}else{
manager.showSoftInputFromInputMethod(mEditText.getWindowToken(), 0);
}
}
public static void openKeyboard(Context context, View view) {
final InputMethodManager imm =
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInputFromInputMethod(view.getWindowToken(), 0);
}
}
/**
* 显示软键盘
* @param activity
*/
public static void showKeyboard(Activity activity) {
if (activity != null) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (!imm.isActive()) {
imm.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0);
}
}
}
/**
* 显示软键盘
*/
public static void showKeyboard(Context context)
{
Activity activity = (Activity) context;
if (activity != null)
{
InputMethodManager imm = (InputMethodManager) activity
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInputFromInputMethod(activity.getCurrentFocus()
.getWindowToken(), 0);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
}
public void showKeyboard(View view) {
if (view != null) {
InputMethodManager imm = (InputMethodManager) getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null)
imm.showSoftInputFromInputMethod(view.getWindowToken(), 0);
}
}
/**
* 显示软键盘
* @param activity
*/
public static void showKeyboard(Activity activity) {
if(activity != null){
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if(!imm.isActive()){
imm.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0);
}
}
}
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.i(TAG, "NotificationReceiver.onReceive called, action=" + action);
if (action.equals(ACTION_SHOW)) {
InputMethodManager imm = (InputMethodManager)
context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInputFromInputMethod(mIME.mToken, InputMethodManager.SHOW_FORCED);
}
} else if (action.equals(ACTION_SETTINGS)) {
context.startActivity(new Intent(mIME, LatinIMESettings.class));
}
}
/**
* 显示软键盘
*/
public static void showKeyboard(Context context) {
Activity activity = (Activity) context;
if (activity != null) {
InputMethodManager imm = (InputMethodManager) activity
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInputFromInputMethod(activity.getCurrentFocus()
.getWindowToken(), 0);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
}
/**
* Show the input method's soft input area, so the user sees the input method window and can interact with it.
* This can only be called from the currently active input method, as validated by the given token.
*
* @param view the current focused view
*/
public static void showSoftInputFromInputMethod(View view) {
if (view != null) {
Context context = view.getContext();
IBinder windowToken = view.getWindowToken();
InputMethodManager inputMethodManager = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInputFromInputMethod(windowToken, 0);
}
}
/**
* 显示软键盘
* @param activity
*/
public static void showKeyboard(Context context) {
Activity activity = (Activity) context;
if(activity != null){
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
}
public void showSoftInput() {
InputMethodManager manager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
manager.showSoftInputFromInputMethod(getWindowToken(), 0);
}
/**
* 显示软键盘(根据焦点所在的控件)
*/
public static void showSoftInput(Context c, View foucsView) {
InputMethodManager imm = (InputMethodManager) c.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInputFromInputMethod(foucsView.getWindowToken(), 0);
}
public static void openKeyboard(Context context, View view) {
InputMethodManager imm = (InputMethodManager) context.getSystemService("input_method");
if (imm != null) {
imm.showSoftInputFromInputMethod(view.getWindowToken(), 0);
}
}