zoukankan      html  css  js  c++  java
  • 点击软键盘外部,收起软键盘

    首先EditText所在的父布局或最外层的布局需要添加属性:
    android:clickable="true"
    android:focusableInTouchMode="true"

    public void setHideKeyBoard(final Context context,EditText etView) { etView.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if(!hasFocus){ hideKeyboardViewCommon(context,view); } } }); } public void hideKeyboardViewCommon(Context context,View view) { InputMethodManager manager = ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)); if (manager != null) manager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); }

    调用:
    //点击软键盘外部,收起软键盘
    DigitKeyboardUtils digitKeyboardUtils = new DigitKeyboardUtils();
    digitKeyboardUtils.setHideKeyBoard(getActivity(),etTransmoney);

    // 进入下一个界面,直接调用 hideKeyboardViewCommon即可,因为EditText没有焦点变化时,调用 setHideKeyBoard 方法不会收起键盘
    DigitKeyboardUtils digitKeyboardUtils = new DigitKeyboardUtils();
    digitKeyboardUtils.hideKeyboardViewCommon(getActivity(),etTransmoney);
    
    
  • 相关阅读:
    codeforces 269B Greenhouse Effect
    codeforces 5C Longest Regular Bracket Sequence
    codeforces 225C Barcode
    codeforces 279C Ladder
    CodeForces 479E Riding in a Lift
    CodeForces 351A Jeff and Rounding
    POJ-1579-201308122106.txt
    表达式求值-201308081712.txt
    Encoding-201308072147.txt
    A + B Problem II201308072001.txt
  • 原文地址:https://www.cnblogs.com/Jackie-zhang/p/14109851.html
Copyright © 2011-2022 走看看