问题标签 [android-vectordrawable]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
android - Android Studio 不会为旧版本从 VectorDrawable 生成 Drawable
我使用 Android Studio 2.0 和支持VectorDrawable
库。我的毕业典礼:
但是当我尝试在旧设备的菜单中加载图标时:
图标是一个矢量,但 AndroidStudio 必须为旧版本生成和绘制(光栅可绘制)。如果不是这样,我需要如何使用它?
向量示例ic_labels_gray_24dp.xml
PS它写了一个简单的类。它不能修复 Android Studio 错误,但至少应用程序不会崩溃。也许其他人也有同样的问题。
android - 如何将 alpha 蒙版应用于 Android 可绘制对象?
在我的应用程序中,我需要更改按钮的背景颜色以响应某些事件。通过设置创建可绘制对象,设置其绘制并将该可绘制对象用作按钮背景,这可以正常工作:
现在,我想在该可绘制对象上覆盖一个 alpha 蒙版,创建一个“条纹”按钮。以下是蓝色和黑色按钮的外观(假设背景颜色为白色,但这些部分实际上应该是 100% 透明的):
我在 Inkscape 中制作了这个 alpha 蒙版,并成功将其作为矢量资产导入。我可能需要将其转换为某种位图,但我不确定。
我已经阅读了一堆文章和提到要应用 PorterDuff 矩阵的 SO 问题,但无法将这些转化为解决我当前的问题。
有人知道怎么做吗?
这是另一个可视化,希望能让事情更清楚。此处按钮的父视图的背景颜色为淡粉色,按钮边框以红色勾勒(但在最终产品中应该是不可见的):
android - 如何保持 VectorDrawable 的纵横比?
我一直在尝试为 Android 应用程序创建启动屏幕,如 正确的启动屏幕 |中所述。有风格的大书呆子牧场
background_splash 看起来像
sparrow.xml 看起来像
但是,我看到的问题是,由宽度和高度属性定义的 1:1 纵横比vector
在设备屏幕上显示时不会保持不变。比如在android studio中显示一个圆圈如下
但是,上面的图像在设备上显示如下,因为它占据了所有可用的高度。
android - Programmatically tint a Support Vector
Android Studio version 2.1, gradle version 2.1.0, please correct me if you spot any misinterpretations :)
I am confused about support vectors in the support library 23.3.0. Specifically what I would like to do is tint an image button programmatically, whose src is defined is a vector drawable. From what I can tell this is not possible on pre-lollipop now.
I have read several related posts about the changes: 23.2.0 announcement and changes:
As of Android Support Library 23.3.0, support vector drawables can only be loaded via app:srcCompat or setImageResource().
Does the above mean that vector xmls can only be used pre-Lollipop via srcCompat or setImageResource(), and therefore cannot be dynamically tinted?
Here is my basic image button:
Works on Lollipop and above only:
Attempting this pre-lollipop throws:
android.content.res.Resources$NotFoundException: File res/drawable/ic_exit_to_app_24dp.xml from drawable resource ID #0x7f0200bf
Also works on Lollipop and above only
This throws the same error on pre-Lollipop.
However if I remove vectorDrawables.useSupportLibrary = true
as pointed out by Ian Lake here, with the intent of having the build tools auto-generate pngs for pre-Lollipop devices, the pngs do not tint on pre-lollipop, so I'm back to square one.
I have also tried specifying the vector via srcCompat
and retrieving it programmatically but I don't think I've been able to achieve that, even though it works on post-Lollipop if the vector is specified using src
instead.
So the situation for 23.3.0 seems to be:
Post-Lollipop:
src
andsrcCompat
accept vectors, onlysrc
can be retrieved from the view as a drawable for tinting programmatically. Referencing vectors in code is possible using getDrawable, and they can be tinted.Pre-Lollipop: srcCompat only can accept vectors, cannot be retrieved programmatically from the view for tinting.
setImageResource
can accept vectors, but only ifvectorDrawables.useSupportLibrary = false
, and tinting does not work. Similarly referencing vectors in code is not possible unlessvectorDrawables.useSupportLibrary = false
and tinting does not work.
Working on all versions using pngs:
Addendum:
This technique also works on post-Lollipop, but like the others on pre-Lollipop I get the drawable, but no tinting:
KIND OF SOLUTION:
Thanks to John's answer so far the only fool-proof way I can come up with to tint a support vector is to set a color filter on it - this means the DrawableCompat.setTint()
function is seemingly not functional for me if the drawable in question is a support vector. I'm not sure if this is a legit bug, expected behavior or if I'm just doing something wrong!
Here is the solution I'm going with for the moment:
android - VectorDrawableCompat 绘制带有位移的图标
请解释我如何解决它?我加载矢量可绘制调用VectorDrawableCompat.create(context.getResources(), resId, context.getTheme());
它适用于所有支持的设备(从 API 8 开始),但绘制所有带有位移的图标。为什么?我无法理解。例如,它的NavigationView
菜单:
布局边界:
build.gradle
示例VectorDrawable
PS 我在带有软件渲染的 Android 6.0 模拟器上制作了这个截图(Ubuntu 16.04 和 radeon HD 5xxx,我很幸运)。不幸的是,我没有真正的设备所以...可能是由于软件渲染?
android - 可绘制为应用程序徽标的矢量
我们可以在 Manifest 文件中使用 Vector drawable 作为 App 标志吗?
我正在为我的应用程序徽标使用这样的可绘制对象,它运行良好。
但是当我尝试在 Playstore 上上传应用程序的发布版本时,它会显示一个错误,指出Invalid Logo。
那么是不是因为我使用矢量可绘制作为应用程序徽标的原因。所以不能为 App logo 使用 drawables 吗?如果我们可以那么如何('因为矢量drawables进入drawables文件夹而不是mipmap)?
android - 精确控制 Android 的 VectorDrawable 动画
更新:找到解决方案!向下滚动查看我接受的答案!
我想为一个图像的多个元素设置动画并将动画链接到 ViewPagers 位置(因此多个元素正在变形或飞入/飞出,具体取决于被拖动的当前页面)。
那么,有没有办法精确控制动画的当前帧呢?例如,假设我有这个集合:
动画矢量文件:
运行动画的 Java 代码:
有没有一种方法可以控制动画setCurrentDuration(400)
,大概会将动画的当前状态设置为一半?也许有一种方法可以将该矢量可绘制对象拆分为图层并以编程方式对其进行动画处理?提前致谢!
java - 如何以编程方式设置 Vector Drawable 的组参数?
我有一个矢量可绘制对象,我想根据我的应用程序中的一些输入来旋转它。
我有一个vector_drawable.xml
在我的代码中,我创建了一个 ValueAnimator
animatorUpdateListener 定义如下:
然后在我的 onDraw 方法中调用
我如何能够更改我的vector_drawable.xml 中的android:rotation
参数,而不是旋转画布?rotation_group
非常感谢!
android - vector drawable not visible in api level 15 even after using the appCompat library version 23.3.0
I am using a vector drawable in an ImageView in API level 15. I am using the AppCompat library version "appcompat-v7:23.3.0" in my gradle, which brings in the support of SVG for lower API levels.
Here is my XML for ImageView:
This is the check.xml in drawable folder:
The ImageView is not being displayed at all. Can anyone please tell what is the mistake I am doing.