微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

考虑这个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

希望这可以帮助!

原文地址:https://www.jb51.cc/android/313983.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐