我有一个九补丁图像并给它起了这样的名字:
img.9.png
当我将它导入到 drawable-hdpi 或 drawable-xhdpi 文件夹等时,android studio 无法识别图像并给我一个错误:
Couldn't resolve resource @mipmap/img.9
Failed to convert @mipmap/img.9 into a drawableError:(69, 29) No resource found that matches the given name (at 'background' with value '@drawable/img').
此外,当我将这个 9patch 图像导入 drawable 文件夹时,android studio 会正确显示它,但是当我构建和运行应用程序时会出现错误:
Error:(69, 29) No resource found that matches the given name (at 'background' with value '@mipmap/img.9').
最佳答案
扩展名必须是 .9.png 但您不必在引用中包含 .9!
所以,它不是@mipmap/img.9
,而是@mipmap/img
此外,mipmap
只能用于启动器图标,不能用于图形资源。
关于Android Studio 无法识别可绘制对象中的 9patch 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32582078/