本文整理了Java中android.view.Window.getCurrentFocus()
方法的一些代码示例,展示了Window.getCurrentFocus()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Window.getCurrentFocus()
方法的具体详情如下:
包路径:android.view.Window
类名称:Window
方法名:getCurrentFocus
暂无
代码示例来源:origin: Jacksgong/JKeyboardPanelSwitch
@Override
public void recordKeyboardStatus(Window window) {
final View focusView = window.getCurrentFocus();
if (focusView == null) {
return;
}
if (isKeyboardShowing) {
saveFocusView(focusView);
} else {
focusView.clearFocus();
}
}
代码示例来源:origin: square/assertj-android
public WindowAssert hasCurrentFocus(View view) {
isNotNull();
View actualView = actual.getCurrentFocus();
assertThat(actualView) //
.overridingErrorMessage("Expected current focused view <%s> but was <%s>.", view,
actualView) //
.isSameAs(view);
return this;
}
代码示例来源:origin: goweii/AnyLayer
private boolean isViewFocus() {
boolean focus = false;
if (focusViews == null || focusViews.length == 0) {
focus = true;
} else {
View focusView = window.getCurrentFocus();
for (EditText editText : focusViews) {
if (focusView == editText) {
focus = true;
break;
}
}
}
return focus;
}
代码示例来源:origin: jruesga/rview
public static void hideSoftKeyboard(Context context, Window window) {
if (window == null) {
return;
}
View view = window.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(
Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}
代码示例来源:origin: stackoverflow.com
public static void hideKeyboard(Activity activity) {
if (activity != null) {
Window window = activity.getWindow();
if (window != null) {
View v = window.getCurrentFocus();
if (v != null) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm!=null){
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
}
}
}
代码示例来源:origin: qyxxjd/BaseProject
/**
* 强制关闭输入法
*/
public static void hide(@NonNull Activity activity) {
//noinspection ConstantConditions
hide(activity.getWindow().getCurrentFocus());
}
代码示例来源:origin: qyxxjd/AndroidBasicProject
/**
* 强制显示输入法
*/
public static void show(Activity activity) {
show(activity.getWindow().getCurrentFocus());
}
代码示例来源:origin: qyxxjd/AndroidBasicProject
/**
* 强制关闭输入法
*/
public static void hide(Activity activity) {
hide(activity.getWindow().getCurrentFocus());
}
代码示例来源:origin: qyxxjd/BaseProject
/**
* 强制显示输入法
*/
public static void show(@NonNull Activity activity) {
//noinspection ConstantConditions
show(activity.getWindow().getCurrentFocus());
}
代码示例来源:origin: Numbrs/RxPhoenix
public void hideKeyboardIfShown() {
View v = getWindow().getCurrentFocus();
if (v != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
代码示例来源:origin: moz1q1/WalleLibrary
/**
* 判断当前软键盘是否打开
*
* @param activity
* @return
*/
public static boolean isSoftInputShow(Activity activity) {
// 虚拟键盘隐藏 判断view是否为空
View view = activity.getWindow().peekDecorView();
if (view != null) {
// 隐藏虚拟键盘
InputMethodManager inputmanger = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
// inputmanger.hideSoftInputFromWindow(view.getWindowToken(),0);
return inputmanger.isActive() && activity.getWindow().getCurrentFocus() != null;
}
return false;
}
代码示例来源:origin: blockchain/Android-Merchant-App
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
boolean ret = super.dispatchTouchEvent(event);
View view = this.getCurrentFocus();
if (view instanceof EditText) {
View w = this.getCurrentFocus();
int scrcoords[] = new int[2];
w.getLocationOnScreen(scrcoords);
float x = event.getRawX() + w.getLeft() - scrcoords[0];
float y = event.getRawY() + w.getTop() - scrcoords[1];
if (event.getAction() == MotionEvent.ACTION_UP && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom()) ) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
}
}
return ret;
}
代码示例来源:origin: luckybilly/DebugController
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
View currentFocus = getWindow().getCurrentFocus();
if (currentFocus != null) {
InputMethodManager imm = (InputMethodManager)getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
//login_auto_account.setCursorVisible(false);
imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
currentFocus.clearFocus();
}
return super.dispatchTouchEvent(ev);
}
}
代码示例来源:origin: com.squareup.assertj/assertj-android
public WindowAssert hasCurrentFocus(View view) {
isNotNull();
View actualView = actual.getCurrentFocus();
assertThat(actualView) //
.overridingErrorMessage("Expected current focused view <%s> but was <%s>.", view,
actualView) //
.isSameAs(view);
return this;
}
代码示例来源:origin: adafruit/Bluefruit_LE_Connect_Android
@Override
public void onKey(int primaryCode, int[] keyCodes) {
View focusCurrent = mActivity.getWindow().getCurrentFocus();
if (focusCurrent != null && (focusCurrent instanceof EditText)) {
EditText edittext = (EditText) focusCurrent;
Editable editable = edittext.getText();
int start = edittext.getSelectionStart();
if (primaryCode == kKeyDelete) {
if (editable != null && start > 0) editable.delete(start - 1, start);
} else if (primaryCode == kKeyReturn) {
View nextFocusView = edittext.focusSearch(View.FOCUS_DOWN);
if (nextFocusView != null && (nextFocusView instanceof EditText)) {
nextFocusView.requestFocus();
} else {
hideCustomKeyboard();
}
} else {
editable.insert(start, Character.toString((char) primaryCode));
}
}
}
代码示例来源:origin: GeorgeArgyrakis/FloatingKeyboard
View focusCurrent = ((Activity) getContext()).getWindow().getCurrentFocus();
if (focusCurrent == null || (focusCurrent.getClass() != EditText.class
&& focusCurrent.getClass().getSuperclass()!= EditText.class) ) return;
内容来源于网络,如有侵权,请联系作者删除!