0

customauto EditText フィールドを作成しました。テキスト フィールドに関する私の問題は、EditText をクリックするとキーボードが上昇するが、他の場所をクリックするとキーボードが開いたままになることです。この問題で私を助けてください

カスタム自動 EditText の名前は auto_list です。onFocusChangeListener を添付しました

auto_list.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
            public void onFocusChange(View v, boolean hasFocus) {
                // TODO Auto-generated method stub
                if (hasFocus) {
                    getActivity()
                            .getWindow()
                            .setSoftInputMode(
                                    WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
                }
                else{
                    InputMethodManager im = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                    im.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
            }
        });
4

4 に答える 4

1

以下のコードを試してください

public static void hideKeyboard(Activity activity) {
     InputMethodManager inputManager = (InputMethodManager) activity
       .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputManager != null && activity.getCurrentFocus() != null) {
      inputManager.hideSoftInputFromWindow(activity.getCurrentFocus()
     .getWindowToken(), 0);
    }
}
于 2013-11-12T09:45:00.810 に答える
0

これを試して :

try
    {
        InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
     }
    catch (Exception e)
    {
        // Ignore exceptions if any
            Log.e("KeyBoardUtil", e.toString(), e);
    }
于 2013-11-12T09:45:57.763 に答える
0

ソフトキーボードを非表示にするイベントでこれを行います...

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(xxx.getWindowToken(), 0);

xxx、キーボードを非表示にする編集テキストです。同じ機能を適用したい編集テキストが複数ある場合も同様です。

于 2013-11-12T09:46:49.443 に答える