how to set only numeric value for EditTextPreference in android?

前端 未结 6 2101
轻奢々
轻奢々 2020-12-15 15:15

how to set only numeric value for EditTextPreference in android. I want a user to enter a port number not sure how can I put the limitation there

I am using this co

6条回答
  •  青春惊慌失措
    2020-12-15 15:55

    Access the EditTextPreference's EditText methods with getEditText and set the input type

    EditTextPreference pref = (EditTextPreference) findPreference("pref_edit_text");
    if (pref != null) {
        pref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
    }
    

    Unfortunate the offical library android.support.v7.preference hide access to getEditText, but there is a fix library that soloves this.

提交回复
热议问题