gpt4 book ai didi

Android VectorDrawable 作为复合绘图

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:33:23 26 4
gpt4 key购买 nike

截至 this android developer blog post 所述,我们现在可以使用 AppCompat 23.2.0 及更高版本在 Android API 7+ 上使用 VectorDrawables

一切对我来说似乎都很好,除了将可绘制对象用作 TextView 的复合物时。

通常,人们会做这样的事情:

            customTab.setCompoundDrawablesWithIntrinsicBounds(
0,
R.drawable.my_vector,
0,
0
);

不幸的是,目前这不起作用,我无法找到解决此问题的方法。

正如帖子所述,唯一可用和有效的方法是 xml 方法,使用 app:srcCompat="@drawable/..." 和 Java setImageResource(。 ..)

如何通过 setCompoundDrawable() 方法使用新的矢量绘图支持?

提前致谢。

编辑:

根据要求,这是 VectorDrawableCompat 类的结果:

explore tab

xml 是:

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="98"
android:viewportHeight="102">

<path
android:fillColor="#4D4D4D"
android:strokeWidth="2"
android:strokeColor="#4D4D4D"
android:pathData="M63.3336386,72.2631001 C56.7778507,76.9021242
48.7563953,79.6307404
40.09319,79.6307404 C17.9503315,79.6307404 0,61.804793 0,39.8153702
C0,17.8259473 17.9503315,0 40.09319,0 C62.2360484,0 80.1863799,17.8259473
80.1863799,39.8153702 C80.1863799,50.8100816 75.6987973,60.7639242
68.4433567,67.9690887 L96.7320074,96.0617174 C98.0293966,97.3501165
97.9978616,99.4159703 96.6953405,100.709466 C95.3837385,102.011979
93.2974318,102.019264 92.0151615,100.745879 L63.3336386,72.2631001
L63.3336386,72.2631001 L63.3336386,72.2631001 Z M40.09319,74.9465792
C59.6310061,74.9465792 75.4695341,59.217802 75.4695341,39.8153702
C75.4695341,20.4129383 59.6310061,4.6841612 40.09319,4.6841612
C20.5553738,4.6841612 4.71684588,20.4129383 4.71684588,39.8153702
C4.71684588,59.217802 20.5553738,74.9465792 40.09319,74.9465792
L40.09319,74.9465792 L40.09319,74.9465792 Z" />
</vector>

最佳答案

support library 23.2开始您可以使用下一个解决方案:

Drawable drawable=AppCompatDrawableManager.get().getDrawable(mContext, R.drawable.drawable);
view.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);

关于Android VectorDrawable 作为复合绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37131642/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com