zoukankan      html  css  js  c++  java
  • 输入法的工具类

    public class InputUtil {
    
        private static InputUtil instance;
        private InputMethodManager mInputMethodManager;
        private static Activity mActivity;
    
        private InputUtil() {
            mInputMethodManager = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
        }
    
        public static InputUtil getInstance(Activity activity) {
            mActivity = activity;
            if (instance == null) {
                instance = new InputUtil();
            }
            return instance;
        }
    
        /**
         * 强制显示输入法
         */
        public void show() {
            show(mActivity.getWindow().getCurrentFocus());
        }
        
        public void show(View view) {
            mInputMethodManager.showSoftInput(view, InputMethodManager.SHOW_FORCED);
        }
    
        /**
         * 强制关闭输入法
         */
        public void hide() {
            hide(mActivity.getWindow().getCurrentFocus());
        }
        
        public void hide(View view) {
            mInputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    
        /**
         * 如果输入法已经显示,那么就隐藏它;如果输入法现在没显示,那么就显示它
         */
        public void showOrHide() {
            mInputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
        }
        
        
    }
  • 相关阅读:
    Prim算法的3个版本
    [转]"undefined reference to" 问题解决方法
    C/C++ 读写 Excel
    Poj 3468
    关于PS中矩形工具的学习
    PS初学习
    java第二天学习。
    Java学习第一天
    二叉树的线索化
    struct files_struct
  • 原文地址:https://www.cnblogs.com/tianzhijiexian/p/4460151.html
Copyright © 2011-2022 走看看