亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

軟鍵盤管理

標簽:
Android

 安卓开发一般都需要进行软键盘管理,常用操作老司机已为你封装完毕,你可以用这份工具进行管理,具体可以查看源码,现在为你开车,Demo传送门

站点

软键盘管理  AppKeyBoardMgr

openKeybord      : 打卡软键盘
closeKeybord     : 关闭软键盘
TimerHideKeyboard: 通过定时器强制隐藏虚拟键盘
isKeybord        : 输入法是否显示
hideInputMethod  : 隐藏输入法
showInputMethod  : 显示输入法

具体路线

public class AppKeyBoardMgr {

/**
 * 打开软键盘
 *
 * @param mEditText  输入框
 * @param mContext   上下文
 */public static void openKeybord(EditText mEditText, Context mContext){
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(mEditText, InputMethodManager.RESULT_SHOWN);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}/**
 * 关闭软键盘
 *
 * @param mEditText 输入框
 * @param mContext  上下文
 */public static void closeKeybord(EditText mEditText, Context mContext){
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
}/**
 * 通过定时器强制隐藏虚拟键盘
 */public static void TimerHideKeyboard(final View v) {
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {        @Override
        public void run() {
            InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);            if (imm.isActive()) {
                imm.hideSoftInputFromWindow(v.getApplicationWindowToken(),0);
            }
        }
    }, 10);
}/**
 * 输入法是否显示
 */public static boolean KeyBoard(EditText edittext) {    boolean bool = false;
    InputMethodManager imm = (InputMethodManager) edittext.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);    if (imm.isActive()) {
        bool = true;
    }    return bool;
}/**
 * 切换软键盘的状态
 * 如当前为收起变为弹出,若当前为弹出变为收起
 */public static void toggleKeybord(EditText edittext) {
    InputMethodManager inputMethodManager = (InputMethodManager)
        edittext.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}/**
 * 强制隐藏输入法键盘
 */public static void hideKeybord(EditText edittext) {
    InputMethodManager inputMethodManager = (InputMethodManager)
        edittext.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);    if (inputMethodManager.isActive()) {
        inputMethodManager.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
    }
}/**
 * 强制显示输入法键盘
 */public static void showKeybord(EditText edittext) {
    InputMethodManager inputMethodManager = (InputMethodManager)
        edittext.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.showSoftInput(edittext, InputMethodManager.SHOW_FORCED);
}/**
 * 输入法是否显示
 */public static boolean isKeybord(EditText edittext) {    boolean bool = false;
    InputMethodManager inputMethodManager = (InputMethodManager)
        edittext.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);    if (inputMethodManager.isActive()) {
        bool = true;
    }    return bool;
}/**
 * 隐藏输入法
 *
 * @param mAct activity
 */public static void hideInputMethod(Activity mAct) {    try {// hide keybord anyway
        View v = mAct.getWindow().getCurrentFocus();        if (v != null) {
            InputMethodManager imm = (InputMethodManager) mAct.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
    } catch (Exception e) {
    }
}/**
 * 显示输入法
 *
 * @param mAct activity
 */public static void showInputMethod(final Activity mAct) {
    View v = mAct.getCurrentFocus();    if (null == v) {        return;
    }
    ((InputMethodManager) mAct.getSystemService(Activity.INPUT_METHOD_SERVICE)).showSoftInput(v, 0);
}

}

终点站

  好了,终点站到了,如果对本次旅途满意的话,请给五星好评哦,没关注的小伙伴轻轻点个上方的关注,毕竟老司机牺牲了很多时间才换来这么一份工具类,如果该工具类依赖其他工具类,都可以在我的史上最全的常用开发工具类收集(持续更新中)中找到。

原文链接:http://www.apkbus.com/blog-703583-68539.html

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消