DevilUtil.java
1.73 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
package com.cnlive.gundam.user.util;
import android.os.IBinder;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
/**
* Created by luxiaoman on 2017/2/16.
*/
public class DevilUtil {
/**
* 根据EditText所在坐标和用户点击的坐标相对比,来判断是否隐藏键盘,因为当用户点击EditText时没必要隐藏
*
* @param v
* @param event
* @return
*/
public static boolean isShouldHideInput(View v, MotionEvent event){
if(v !=null&&(v instanceof EditText)){
int[] l ={0,0};
v.getLocationInWindow(l);
int left=l[0],top=l[1],bottom=top+v.getHeight(),right=left
+v.getWidth();
if(event.getX()>left&&event.getX()<right
&&event.getY()>top&&event.getY()<bottom){
// 点击EditText的事件,忽略它。
return false;
}else{
// hideSoftInput(v.getWindowToken());
return true;
}
}
// 如果焦点不是EditText则忽略,这个发生在视图刚绘制完,第一个焦点不在EditView上,和用户用轨迹球选择其他的焦点
return false;
}
/**
* 多种隐藏软件盘方法的其中一种
*
* @param token
*/
public static void hideSoftInput(IBinder token, InputMethodManager im){
if(token!=null){
im.hideSoftInputFromWindow(token,
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}