1
This commit is contained in:
42
app/src/main/java/utils/UtilHelpers.java
Normal file
42
app/src/main/java/utils/UtilHelpers.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.IBinder;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
|
||||
public class UtilHelpers {
|
||||
/**
|
||||
* 根据传入控件的坐标和用户的焦点坐标,判断是否隐藏键盘,如果点击的位置在控件内,则不隐藏键盘
|
||||
*
|
||||
* @param view 控件view
|
||||
* @param event 焦点位置
|
||||
* @return 是否隐藏
|
||||
*/
|
||||
public static boolean hideKeyboard(MotionEvent event, View view,
|
||||
Activity activity) {
|
||||
|
||||
try {
|
||||
if (view != null && view instanceof EditText) {
|
||||
int[] location = {0, 0};
|
||||
view.getLocationInWindow(location);
|
||||
int left = location[0], top = location[1], right = left
|
||||
+ view.getWidth(), bootom = top + view.getHeight();
|
||||
// 判断焦点位置坐标是否在空间内,如果位置在控件外,则隐藏键盘
|
||||
if (event.getRawX() < left || event.getRawX() > right
|
||||
|| event.getY() < top || event.getRawY() > bootom) {
|
||||
// // 隐藏键盘
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user