考虑这个preferences.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/preference_main">
<PreferenceScreen
android:title="@string/preference_sight"
android:key="category_sight">
<ListPreference
android:summary="@string/preference_sight_wb_msg"
android:title="@string/preference_sight_wb_title"
android:key="sight_wb" android:defaultValue="auto"/>
<Preference
android:key="sight_wb_values_cache"/>
<eu.elevelcbt.sm.preferences.PercentBarPreference
android:title="@string/preference_sight_mean_confidence_min_title"
android:summary="@string/preference_sight_mean_confidence_min_msg"
android:key="sight_mean_confidence_min"
android:defaultValue="80"/>
<CheckBoxPreference
android:key="sight_flash"
android:defaultValue="false"
android:summary="@string/preference_sight_flash_msg"
android:title="@string/preference_sight_flash_title"/>
</PreferenceScreen>
</PreferenceScreen>
在我的MainPreference类中显示时,PreferenceActivity正确显示了一个第一级菜单,其中包含一个条目“Sight”(@ string / preference_main),当选中该条目时,会将我带到第二个首选项屏幕,其中包含我的所有首选项.一切都按我想要的方式运作.唯一的事情是在第一个首选项屏幕上,我想在标签“Sight”旁边放置一个图标,就像在主Android设置菜单中一样.
我怎样才能做到这一点?非常感谢您的任何帮助!
卢卡.
矿:
期望:
……嗯我试过但没有运气……
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/preference_main">
<PreferenceScreen
android:title="@string/preference_sight"
android:key="category_sight"
android:icon="@drawable/ic_dialog_light">
...
</PreferenceScreen>
我哪里做错了?
解决方法
您可以查看设置应用程序的源代码,看看他们正在扩展Preference以执行此操作.这是类文件.
https://github.com/android/platform_packages_apps_settings/blob/master/src/com/android/settings/IconPreferenceScreen.java
希望这可以帮助!