0

EditTextPreferenceで動的に読み込まれるカスタムXMLレイアウトにEditTextがあります。すべてがうまくいく。プリファレンスがクリックされ、editPreferenceダイアログが表示されたら、ソフトキーボードも表示されます。私はソフトキーボードをデフォルトで表示したくありません!EditTextPreferenceのソフトキーボードを非表示にできない

これは私が試みたものです。働いているはずです:(

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); 

     } 

} 
+0

ユーザーがEditTextをタップすると、ソフトキーボードが表示されますか?そうですか? – Herry

+0

EditTextにはデフォルトでフォーカスが設定されているため、ソフトキーボードは自動的に –

+0

と表示されるので、ソフトキーボードをデフォルトで開かないようにします。 – Herry

答えて

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; 
     } 
    }); 
+0

動作しますが、回避策が悪いユーザーエクスペリエンスです。キーボードが表示され、元に戻ってきます。 doesntはきちんと見える!それにもかかわらず+1。 Thnx! –

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()); 
     } 
    } 
関連する問題