android - 如何将图标添加到首选项

标签 android icons screen preferences

我正在制作一个扩展 PreferenceActivity 的应用,我想为每个 Preference 添加一个图标。

我读到了一个类似的问题,这是更有名气的答案:

CommonsWare 说:

The Settings application uses a private custom PreferenceScreen subclass to have the icon -- IconPreferenceScreen. It is 51 lines of code, including the comments, though it also requires some custom attributes. The simplest option is to clone all of that into your project, even though you do not like that.

但我不能让它工作。现在我将 IconPreferenceScreen 类克隆到我的项目中。而且我不知道在这之后我要做什么。我正在尝试制作一个新的 IconPreferenceScreen 我无法让它工作..

    IconPreferenceScreen test = new IconPreferenceScreen();
    test.setIcon(icon);

最佳答案

今天你可以使用自 API 11 起可用的 android:icon attr :)

关于android - 如何将图标添加到首选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5765186/

相关文章:

android - 更改 ListView 中所选项目的背景颜色和字体颜色

Android - 指纹信息存储在设备中的位置和安全程度

Android 未在 ionic 应用程序中请求权限

javascript - 检查显示是否支持 JavaScript 中的 HDR(高动态范围)颜色?

android - 如何在没有状态栏和操作栏的情况下获取屏幕高度(像素)?

android - 是否可以在 android 的同一个选项卡中打开新的 Intent ?

java - Android开发IDE的 future ,eclipse还是Android Studio

ubuntu - ubuntu 16.04 Unity 中的 Docker 图标系统托盘

flutter - 如何更改 Flutter 底部导航栏中的 SVG 图标?

html - 很棒的字体不适用于任何 iE 或 Edge