0

EditTextPreference で動的にロードされる (setView) カスタム xml レイアウトに EditText があります。すべてがうまく機能します。設定がクリックされ、editPreference ダイアログが表示されると、ソフト キーボードも表示されます。デフォルトでソフトキーボードを表示したくありません!

これは私が試したものです。うまくいったはずです:(!

public class ReportBugPreference extends EditTextPreference {


        @Override
        protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
            super.onPrepareDialogBuilder(builder);  

            View viewBugReport = LayoutInflater.from(ctx).inflate(R.layout.preference_report_bug,null);
            builder.setView(viewBugReport);

            EditText edttxtBugDesc = (EditText) viewBugReport.findViewById(R.id.bug_description_edittext);
            //edttxtBugDesc.clearFocus();

            InputMethodManager inputManager = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(edttxtBugDesc.getApplicationWindowToken(), 0);

        }

}
4

2 に答える 2

1

EditTextに対してこれを実行して、ソフトキーボードを非表示にします

       mEditText.requestFocus();
       mEditText.postDelayed(new Runnable() {
                @Override
                public void run() {
                    InputMethodManager keyboard = (InputMethodManager)
                    getSystemService(Context.INPUT_METHOD_SERVICE);
                    keyboard.hideSoftInputFromWindow(ettext.
                                                       getWindowToken(), 0);
                }
            },200);

これを行うためのより良い方法はコードの下にあると思います:

    mEditText.setInputType(InputType.TYPE_NULL);
    mEditText.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
             mEditText.setInputType(InputType.TYPE_CLASS_TEXT);
            return false;
        }
    });
于 2012-04-25T10:59:44.057 に答える
0

役立つ可能性のあるジェネリック関数。

 public static void hideSoftKeyboard (Context context, View view) {
        try {
            InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
        }
        catch (Exception ex) {
            Log.w(TAG, "hideSoftKeyboard->"+ex.toString());
        }
    }
于 2012-04-25T11:04:18.160 に答える