我有一个preferences.xml,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:name="Sample"
android:enabled="true"
android:persistent="true"
android:summary="Sample"
android:defaultValue="3.0"
android:title="Sample"
android:key="sample" />
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
当我执行sp.getString("sample","3.0")时,它工作正常并返回一个字符串,但它不应该是一个字符串,它应该是一个浮点数.运行sp.getFloat("sample",3.0f)会抛出ClassCastException,因为它是一个字符串.
我应该在XML中放置什么以便将首选项存储为浮点数?