package com.mgq.base.utils.keyboard;

import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

/**
 * Created by Administrator on 2016/07/25.
 */
public class KeyBoard {
    private  Context mContext;
    private  EditText mEditText;

    public KeyBoard(Context mContext, EditText mEditText) {
        this.mContext = mContext;
        this.mEditText = mEditText;
    }

    //打开软键盘
    public  void openKeybord() {
        InputMethodManager imm = (InputMethodManager) mContext
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(mEditText, InputMethodManager.RESULT_SHOWN);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
                InputMethodManager.HIDE_IMPLICIT_ONLY);
    }

    // 关闭键盘
    public void closeKeybord() {
        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);

        imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
    }
}
