android – 如何向PreferenceScreen条目添加图标

前端之家收集整理的这篇文章主要介绍了android – 如何向PreferenceScreen条目添加图标前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
考虑这个preferences.xml文件
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <PreferenceScreen
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:title="@string/preference_main">
  5. <PreferenceScreen
  6. android:title="@string/preference_sight"
  7. android:key="category_sight">
  8. <ListPreference
  9. android:summary="@string/preference_sight_wb_msg"
  10. android:title="@string/preference_sight_wb_title"
  11. android:key="sight_wb" android:defaultValue="auto"/>
  12. <Preference
  13. android:key="sight_wb_values_cache"/>
  14. <eu.elevelcbt.sm.preferences.PercentBarPreference
  15. android:title="@string/preference_sight_mean_confidence_min_title"
  16. android:summary="@string/preference_sight_mean_confidence_min_msg"
  17. android:key="sight_mean_confidence_min"
  18. android:defaultValue="80"/>
  19. <CheckBoxPreference
  20. android:key="sight_flash"
  21. android:defaultValue="false"
  22. android:summary="@string/preference_sight_flash_msg"
  23. android:title="@string/preference_sight_flash_title"/>
  24. </PreferenceScreen>
  25. </PreferenceScreen>

在我的MainPreference类中显示时,PreferenceActivity正确显示了一个第一级菜单,其中包含一个条目“Sight”(@ string / preference_main),当选中该条目时,会将我带到第二个首选项屏幕,其中包含我的所有首选项.一切都按我想要的方式运作.唯一的事情是在第一个首选项屏幕上,我想在标签“Sight”旁边放置一个图标,就像在主Android设置菜单中一样.

我怎样才能做到这一点?非常感谢您的任何帮助!
卢卡.

矿:

期望:

……嗯我试过但没有运气……

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <PreferenceScreen
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:title="@string/preference_main">
  5. <PreferenceScreen
  6. android:title="@string/preference_sight"
  7. android:key="category_sight"
  8. android:icon="@drawable/ic_dialog_light">
  9. ...
  10. </PreferenceScreen>

我哪里做错了?

解决方法

您可以查看设置应用程序的源代码,看看他们正在扩展Preference以执行此操作.这是类文件.

https://github.com/android/platform_packages_apps_settings/blob/master/src/com/android/settings/IconPreferenceScreen.java

希望这可以帮助!

猜你在找的Android相关文章