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 开发中,pullToRefreshListView 的刷新,加载
  2. Android Studio 添加百分比布局库的依赖报错 第一行代码
  3. 简单布局收缩动画
  4. Android C++ 动态加载so
  5. android中setImageResource加载大图片出现oom解决方案
  6. Android 基础布局控件自定义view使用练习
  7. Android加载Gif动画实现代码

随机推荐

  1. Transparent Activity
  2. Android(安卓)下实现带有图标和Checkbox
  3. Android(安卓)去除String中的空格等
  4. android获取本机的IP地址和mac物理地址
  5. Android(安卓)打印堆栈
  6. Android(安卓)实现再按一次后退键退出应
  7. asynchttpclient post方法使用
  8. android 多点触摸 实现图片缩放 Image Zo
  9. How to set up a link betwteen a real A
  10. android 按钮的文字显示不全