【发布时间】:2014-10-27 16:37:16
【问题描述】:
我有一个 EditTextPreference 供用户在我的preferences.xml 文件中输入蓝牙 MAC 地址。我正在使用 android:digits 将输入限制为有效字符,但这不会阻止某人添加太少或太多字符、双冒号等。如果他们这样做,应用程序会因无效的 MAC 地址异常而崩溃。有没有办法以编程方式做到这一点?
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Bluetooth Settings">
<EditTextPreference
android:key="prefMacAddress"
android:title="MAC Address"
android:lines="1"
android:maxLines="1"
android:summary="Enter MAC Address of the Module"
android:dialogTitle="MAC Address"
android:dialogMessage="Enter MAC Address of the Module"
android:defaultValue="20:13:07:26:24:32"
android:digits="0123456789abcdef:"/>
</PreferenceCategory>
</PreferenceScreen>
【问题讨论】:
标签: android xml sharedpreferences preferenceactivity