首页 > 解决方案 > 在 android 可绘制项目部分从 mipmap 添加图像

问题描述

下面是我的可绘制代码。我想在可绘制项中添加来自 mipmap 的图像,而不是使用可绘制。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">


    <item android:drawable="@drawable/drawable_selected_indicator"
        android:state_selected="true"/>

    <item android:drawable="@drawable/drawable_default_indicator"/>
</selector>

标签: android

解决方案


您可以使用 @mipmap/filename 来使用 mipmap 文件夹中的图像。

<item android:drawable="@mipmap/drawable_selected_indicator"
    android:state_selected="true"/>

根据这个维基 - https://github.com/codepath/android_guides/wiki/Working-with-the-ImageView

“从 Android 4.3 开始,现在可以选择使用 res/mipmap 文件夹来存储“mipmap”图像。Mipmap 最常用于应用程序图标,例如启动器图标。要了解有关 mipmap 好处的更多信息,请务必查看可绘制的 mipmapping 帖子。

然后可以使用@mipmap/ic_launcher 符号代替@drawable 访问Mipmap 图像资源。将图标放置在 mipmap 文件夹中(而不是可绘制的)被认为是最佳实践,因为它们通常可以在与设备当前密度不同的分辨率下使用。例如,xxhdpi 设备的启动器上可能会使用 xxxhdpi 应用程序图标。”


推荐阅读