gpt4 book ai didi

android - VectorDrawable 向后兼容性和安装非官方支持库

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

请耐心等待,我是新来的!
我想在我的 android 应用程序中使用矢量,并且我希望我的应用程序向后兼容。我找到了 this support library看起来很酷!*
所以我对如何“安装”它感到困惑。它为您提供了下载 .pom、.aar、javadoc.jar 和 sources.jar 文件的链接。我应该下载哪一个,我应该把文件放在哪里(什么文件夹)?
(我正在使用 Android Studio!)
*(有人知道不同的 VectorDrawable 支持库吗?我很想听听大家的经验!)

最佳答案

这是一个对我有用的选项使用此库 - https://github.com/wnafee/vector-compat (API 14+)

android {
// use version 22 or higher
buildToolsVersion "22.0.1"
...
}
dependencies {
compile 'com.wnafee:vector-compat:1.0.5'
...
}

并创建一个使用矢量兼容类的自定义 ImageView 类 -

public class SvgImageView extends ImageView {        
private Drawable icon;


public SvgImageView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray ta = context.obtainStyledAttributes(attrs,
R.styleable.button_left, 0, 0);

try {
int resId = ta.getResourceId(R.styleable.button_left_b_icon, -1);
if (resId != -1) {
icon = ResourcesCompat.getDrawable(this.getContext(), resId);

}


} finally {
ta.recycle();
}


if (icon != null) {
setImage(icon);
}

}

public void setImage(Drawable icon) {
SvgImageView.this.setImageDrawable(icon);

}



}

矢量图像示例 -

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:width="@dimen/logo_dimen"
android:height="@dimen/logo_dimen"
android:viewportWidth="@integer/view_port_dimen_logo"
android:viewportHeight="@integer/view_port_dimen_logo"

app:vc_viewportWidth="@integer/view_port_dimen_logo"
app:vc_viewportHeight="@integer/view_port_dimen_logo">
<group
android:name="rotationGroup"
android:pivotX="0"
android:pivotY="0"
android:rotation="0">

<path
android:name="v"
android:fillColor="@color/white"
android:pathData="m15.5,15.6c0,-1.5 2.8,-1.9 2.8,-5c0,-1.5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5,2.2c2.3,0 4.9,-0.7 6.1,-2.8c0.4,-0.6 0.6,-1.3 0.6,-2.1c0.2,-3.5 -3.6,-4 -3.6,-5.6zm-1.7,-1.2c-2.2,0 -3.2,-2.8 -3.2,-4.6c0,-0.7 0.1,-1.4 0.6,-1.9c0.4,-0.6 1.1,-0.9 1.7,-0.9c2.2,0 3.2,3 3.2,4.8c0,0.7 -0.1,1.4 -0.6,1.9c-0.4,0.4 -1.1,0.7 -1.7,0.7zm0,10.5c-1.9,0 -4.5,-0.8 -4.5,-3.2c0,-2.5 2.9,-3.1 4.9,-3.1c0.2,0 0.4,0 0.6,0c1.2,0.8 2.8,1.8 2.8,3.4c-0.1,2.2 -2,2.9 -3.8,2.9zm9.7,-10.5v-2.6h-1.3v2.6h-2.5v1.3h2.5v2.6h1.3v-2.6h2.6v-1.3h-2.6l0,0z" />

</group>
</vector>

示例 -

<packagename.SvgImageView     

app:b_icon="@drawable/google_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView3" />

关于android - VectorDrawable 向后兼容性和安装非官方支持库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30713093/

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