javaandroidpreferencespreferenceactivitypreferencescreen

How to set focus on editText Preference and show keyboard automatically?


I am learning the Preferences and I have created this

enter image description here

After clicking on EditText I am getting this

enter image description here

What I am trying to do is this.

enter image description here

The keybord and focus on edittext only shows when I click on it. I want it automatically when I click on EditText(This is editxText).


Solution

  • in your preference fragment that extends from PreferenceFragmentCompat override onResume() with below

    @Override
    public void onResume() {
        super.onResume();
        Preference search = findPreference(getString(R.string.setting_edit_text_key));
        search.performClick();
    }
    

    Illustration: you inflate the EditTextPreference using its key, and perform a click on it.