我在我的首选项活动中创建了一个列表首选项,代码为所选项目返回的值是条目的值,而不是条目值的值。
示例:
条目:David 新
值:DAVIDNEW.TTF
代码返回“ David New ”而不是“ DAVIDNEW.TTF ”。
这是代码:
文件preferences.xml
:
<ListPreference
android:key="fontSelect"
android:title="@string/textPrefs"
android:summary="@string/textPrefs"
android:defaultValue="DAVIDNEW.TTF"
android:entries="@array/fonts"
android:entryValues="@array/fontsValues" />
文件arrays.xml
:
<string-array name="fonts">
<item>Alex</item>
<item>Cardo</item>
<item>Chaya</item>
<item>David New</item>
<item>Droid Sans</item>
<item>Frank</item>
<item>Mike Hebrew</item>
</string-array>
<string-array name="fontsValues">
<item>ALEX.TTF</item>
<item>Cardo99s.ttf</item>
<item>CHAYA.TTF</item>
<item>DAVIDNEW.TTF</item>
<item>DroidSansHebrew.ttf</item>
<item>frank.ttf</item>
<item>mike_hebrew_regular_v33.ttf</item>
</string-array>
文件reader.java
:
String f1 = new String(myprefs.getString("fontSelect", "DAVIDNEW.TTF"));
font = Typeface.createFromAsset(getAssets(), f1);
tv.setTypeface(font);
的值f1
是“ David New ”而不是“ DAVIDNEW.TTF ”。