android - 在 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>
解决方案
您可以使用 @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 应用程序图标。”
推荐阅读
- docker - 使用 JDBC 输入插件在 Docker 上的 Logstash 不会从 SQL Server 获取所有行
- flutter - 如何突出显示我在字符串中搜索的确切单词,而不仅仅是字符串的开头?
- flutter - 如何实时获取文档长度
- javascript - Reactjs 从获取请求中返回一个对象
- javascript - Nginx 正在尝试打开文件而不是重定向到代理
- python - _joint_log_likelihood 给我错误的值
- sql - 如何按日期获取最后一件商品的价格
- python-3.x - 定期执行功能而不停止其他操作
- r - 使用 R 从 PDF 表单到数据框的文本挖掘
- r - 如果 r 中出现错误,则转到 lapply() 的下一次迭代