Android的工作室1.4:;文件/新建/矢量资产&QUOT绘制-V21采用&QUOT时忽略;选项
这是我的第一个问题,SO所以请不要吃我还活着......这是我的问题:
This is my first SO question so please don't eat me alive... Here's my problem:
我已经通过Android的工作室1.4的新选项,进口几个图标 - 新/矢量资产
。正如你所知道它可以让你轻松地导入和使用矢量图形内容,并与API和LT的兼容性造成的PNG; 21。它把PNG图像文件夹中的应用程序/编译/生成/ RES / PNG格式/调试/ drawable-<密度GT;
(MDPI,LDPI,华电国际等)。它还生成的所有文件夹的 -v21
版本,并把矢量绘制.xmls那里。
I've imported few icons via Android Studio 1.4's new option - New/Vector Asset
. As you know it lets you easily import and use vector drawables and creates pngs for compatibility with APIs <21. It puts the pngs in folders app/build/generated/res/pngs/debug/drawable-<density>
(mdpi, ldpi, hdpi etc). It also generates the -v21
versions of all the folders and puts the vector drawable .xmls there.
问题开始,当我想涟漪效果添加到其中一个图标。我已经把....纹波更小的版本在我的 RES /绘制
文件夹中。它看起来是这样的:
The problem started, when I wanted to add ripple effect to one of the icons. I've put the .... ripple-less version into my res/drawable
folder. It looked like this:
绘制/ ic_settings.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M12,15.5A3.5,3.5 ...blablabla notimportatnt"/>
</vector>
然后我想纹波添加到API> 21的图标。因此,要在文件夹 RES /绘-V21
我将此绘制:
绘制-V21 / ic_settings.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item>
<vector
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M12,15.5A3.5,3.5 0,0....blah blah blah"/>
</vector>
</item>
</ripple>
现在,当我在API 21上运行,而不是使用资源从绘制-V21的应用程序,
它采用了可绘制从应用程序/建设/生成/ RES / PNG格式/调试/绘-xxhdpi-V21
根据 RES文件自动生成/绘制
。因此,没有波动。
Now, when I run the app under API 21, instead of using resources from drawable-v21
it uses a drawable from app/build/generated/res/pngs/debug/drawable-xxhdpi-v21
automatically generated based on the file in res/drawable
. So no ripple.
当我试图从去除纹波更小的文件 RES /绘制/
,纹波回来的API 21,但当然在API和LT应用程序崩溃; 21
When I tried to remove the ripple-less file from res/drawable/
, the ripple comes back in API 21, but of course the app crashes in APIs<21
然后我试图把图标 RES /绘制
文件夹中的纹波版本,希望会的gradle自动生成PNG图像。都能跟得上 - &LT;纹波GT;
标签prevents从产生的PNG和应用程序崩溃&LT摇篮; 21。
Then I tried to put ripple version of the icon to the res/drawable
folder, hoping that gradle would automatically generate the pngs. Nope - <ripple>
tag prevents gradle from generating pngs and the app crashes <21.
任何偶然发现了这样的问题?任何想法如何添加纹波的图标?
Anyone stumbled upon this kind of problem? Any idea how to add ripple to the icon?
有一个好的一天!
好吧,我有点找到了解决办法。
Ok, I kinda found the solution.
在文件夹 RES /绘制
我离开只是可以而且应该被自动转换成PNG图片的载体 - 所以只是没纹波平原正常的图标。然后在 drawable_v21
我已经把绘制的纹波版本,并更名为 - ic_settings_ripple.xml
。我创建了一个新的文件夹布局-V21
和重复我的布局,但不是 ic_settings.xml
我用 ic_settings_ripple.xml
。
In folder res/drawable
I left only the vectors that can and should be automatically converted to pngs - so only plain normal icons without ripple. Then in drawable_v21
I've put the ripple version of drawable and renamed it - ic_settings_ripple.xml
. I've created a new folder layout-v21
and duplicated my layout, but instead of ic_settings.xml
i used ic_settings_ripple.xml
.
所以,现在下API&LT; 21应用程序使用的gradle所产生的波纹少PNG,并在API> = 21还有另外一个布局,使用的图标之一纹波版本。
So now under API<21 the app uses ripple-less png generated by gradle, and at API>=21 there is an alternative layout, that uses ripple version of one of the icon.