-
Notifications
You must be signed in to change notification settings - Fork 802
/
AppKeyBoardMgr.java
149 lines (136 loc) · 4.61 KB
/
AppKeyBoardMgr.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.jingewenku.abrahamcaijin.commonutil;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import java.util.Timer;
import java.util.TimerTask;
/**
* 主要功能:软键盘管理
*
* @Prject: CommonUtilLibrary
* @Package: com.jingewenku.abrahamcaijin.commonutil
* @author: AbrahamCaiJin
* @date: 2017年05月03日 16:37
* @Copyright: 个人版权所有
* @Company:
* @version: 1.0.0
*/
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);
}
}