当我使用支持库作为首选项时,EditTextPreference 中的 inputType 属性不起作用。
我正在使用的支持库的版本
com.android.support:preference-v7:27.1.1
但是当我使用首选项 fragment 时 inputType 似乎可以工作 有人可以解释为什么吗?
这里是EditTextPreference的代码
<EditTextPreference
android:id="@+id/computer_ip"
android:defaultValue="192.168.0.103"
android:hint="Computer Ip"
android:inputType="numberDecimal"
android:key="@string/computerIp"
android:padding="8dp"
android:textSize="16sp"
android:title="Computer Ip" />
在这段代码中,当使用支持库时,inputType 是 numberDecimal,numberDecimal 对键盘没有任何影响,而是显示带有所有字母的键盘。
最佳答案
有一个简单的解决方案,只需使用
EditTextPreference preference = (EditTextPreference) findPreference("key");
EditText et = preference.getEditText();
if (et != null) {
et.setInputType(InputType.TYPE_CLASS_NUMBER);
//in fact, you can do whatever you can normally with an EditText here
}
关于android - 使用支持首选项 fragment 时 inputType 在 EditTextPreference 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50889283/