Android中软键盘的管理主要是通过InputMethodManager来完成的,

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);

使用方法:

import android.app.Activity;import android.content.Context;import android.view.inputmethod.InputMethodManager;import android.widget.EditText;/** * Created by Administrator on 2017/4/4. * 软键盘工具类 */public class KeyboardUtil {    /**     * 显示软键盘,当布局加载完成后调用,否则无效     * @param context     * @param focusView:必须为EditText或者其子类并且获得焦点,并且是VISIBLE     */    public static void showSoftInput(Context context, EditText focusView){        InputMethodManager inputMethodManager= (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);        if (inputMethodManager != null) {            focusView.requestFocus();            inputMethodManager.showSoftInput(focusView,0);        }    }    /**     * 隐藏软键盘,当布局加载完成后调用,否则无效     * @param context     */    public static void hideSoftInput(Context context){        InputMethodManager inputMethodManager= (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);        if (inputMethodManager != null) {            inputMethodManager.hideSoftInputFromWindow(((Activity)context).getWindow().getDecorView().getWindowToken(),0);        }    }    /**     * 切换软键盘状态(隐藏-显示或显示-隐藏),当布局加载完成后调用,否则无效     * @param context     */    public static void toggleSoftInput(Context context){        InputMethodManager inputMethodManager= (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);        if (inputMethodManager != null) {            inputMethodManager.toggleSoftInput(0,0);        }    }}

参考博客: Android手动显示和隐藏软键盘

更多相关文章

  1. Android弹出软键盘布局是否上移问题
  2. android 属性android:visibility
  3. Android的onCreateOptionsMenu()创建菜单Menu详解
  4. Android(安卓)动画显示文字与bitmap的BadgeView
  5. 2010.12.16——— android listView 显示图片 内存溢出问题
  6. Android(安卓)UI界面基本属性 大全
  7. Android(安卓)软键盘盖住输入框的问题
  8. RecyclerView不显示问题
  9. 设置屏幕显示模式ScreenOrientation.

随机推荐

  1. Android中的消息机制:Handler消息传递机制
  2. Android中的多媒体编程-黄俊东-专题视频
  3. 开发具备语音识别功能的 Android* 应用
  4. android 屏幕自适应
  5. 【Android布局】在程序中设置android:gra
  6. android的Instrumentation详解
  7. Android在Eclipse环境下安装配置
  8. Android中横竖屏切换的问题
  9. Android(安卓)应用程序之间数据共享—Con
  10. 【Android】gravity、layout_gravity 以