InputMethodUtils.java
1.79 KB
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
package com.cnlive.goldenline.util;
import android.content.Context;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
/**
* Created by 大灯泡 on 2016/1/14.
* 显示键盘d工具类
*/
public class InputMethodUtils {
/** 显示软键盘 */
public static void showInputMethod(@NonNull View view) {
// InputMethodManager imm = (InputMethodManager) view.getContext()
// .getSystemService(Context.INPUT_METHOD_SERVICE);
// if (imm != null) {
// imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
// }
InputMethodManager inputManager =(InputMethodManager)view.getContext().
getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(view, 0);
}
/*隐藏软键盘*/
public static void hiddenInputMethod(@NonNull View view){
InputMethodManager imm = (InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(),0);
}
/** 隐藏软键盘 */
public static void hiddenInputMethod(@NonNull Context context) {
InputMethodManager imm = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
/** 多少时间后显示软键盘 */
public static void showInputMethod(@NonNull final View view, long delayMillis) {
// 显示输入法
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
InputMethodUtils.showInputMethod(view);
}
}, delayMillis);
}
}