标签: android-vectordrawable

在Android Studio中更改矢量资产的填充颜色

Android Studio现在支持21岁以上的矢量资产,并将在编译时为较低版本生成png.我有一个矢量资源(来自材料图标)我想要更改填充颜色.这适用于21+,但生成的png不会改变颜色.有没有办法做到这一点?

<vector android:height="48dp" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/primary" android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
Run Code Online (Sandbox Code Playgroud)

android vector-graphics android-studio android-vectordrawable

148
推荐指数
7
解决办法
14万
查看次数

是否可以使用android:DrawableRight在Buttons和TextViews中使用VectorDrawable?

当我在textview或imageview中使用VectorDrawable资源时,使用"android:DrawableRight"/"android:DrawableEnd"/"android:DrawableStart"/"android:DrawableLeft"时会出现运行时崩溃.

该应用程序将编译正常,没有任何警告.

我在用

  • Gradle 1.5
  • 支持库23.2('com.android.support:appcompat-v7:23.2.0')

我发现的是,我可以通过编程方式在Java中分配SVG,而不会像这样崩溃.

TextView tv = (TextView) findViewById(R.id.textView);
tv.setCompoundDrawablesWithIntrinsicBounds(null,null, getResources().getDrawable(R.drawable.ic_accessible_white_36px),null);
Run Code Online (Sandbox Code Playgroud)

(我怀疑这是23.2的支持库错误.)

但是可以将drawableRight等用于SVG资产吗?

这是我的布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="au.com.angryitguy.testsvg.MainActivity">


<TextView
    android:id="@+id/textView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:drawableRight="@drawable/ic_accessible_white_36px"
    android:background="@color/colorPrimary"
    android:textColor="#FFFFFF"
    android:textSize="22sp"
    android:text="Hello World!"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的活动

package au.com.angryitguy.testsvg;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        }
    }
Run Code Online (Sandbox Code Playgroud)

以下是Google材料设计网站中未经修改的VectorDrawable资产.

<vector android:height="24dp" android:viewportHeight="24.0"
    android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#FFFFFF" android:pathData="M12,4m-2,0a2,2 …
Run Code Online (Sandbox Code Playgroud)

java android android-layout compound-drawables android-vectordrawable

117
推荐指数
10
解决办法
5万
查看次数

从矢量drawable获取位图

在我的应用程序中,我必须为通知设置一个大图标.LargeIcon必须是一个Bitmap,我的drawables是矢量图像(Android中的新功能,请看这个链接)问题是当我尝试解码一个矢量图像的资源时,我得到一个null返回.

以下是代码示例:

if (BitmapFactory.decodeResource(arg0.getResources(), R.drawable.vector_menu_objectifs) == null)
        Log.d("ISNULL", "NULL");
    else
        Log.d("ISNULL", "NOT NULL");
Run Code Online (Sandbox Code Playgroud)

在这个例子中,当我用一个"普通"图像替换R.drawable.vector_menu_objectifs,例如一个png例如,结果不为空(我得到正确的位图)是否有我缺少的东西?

android bitmap android-drawable android-vectordrawable

107
推荐指数
5
解决办法
5万
查看次数

如何在不进行缩放的情况下将图层列表中的矢量绘图居中

我试图VectorDrawableLayerList没有缩放矢量的情况下使用a .例如:

<layer-list>
    <item android:drawable="@color/grid_item_activated"/>
    <item android:gravity="center" android:drawable="@drawable/ic_check_white_48dp"/>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

drawable ic_check_white_48dpid定义为:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="48dp"
        android:height="48dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
</vector>
Run Code Online (Sandbox Code Playgroud)

所需的效果是检查图标在图层可绘制的中心,而不进行缩放.问题是,上面的图层列表会导致检查图标缩放以适合图层大小.

如果我用每个密度的PNG替换矢量drawable并修改图层列表,我可以产生所需的效果:

<layer-list>
    <item android:drawable="@color/grid_item_activated"/>
    <item>
        <bitmap android:gravity="center" android:src="@drawable/ic_check_white_48dp"/>
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

我有什么方法可以使用VectorDrawable

android layer-list android-drawable android-vectordrawable

87
推荐指数
4
解决办法
3万
查看次数

VectorDrawable - 它是否适用于Lollipop之前版本的Android?

背景

我注意到Android现在支持某种矢量绘图,通过一个名为" VectorDrawable " 的类(以及AnimatedVectorDrawable,BTW).我通过查看Android-Studio上的新功能找到了它.

我不知道这是否会是具有把多个文件分成多个文件夹(年底mdpi,hdpi,xhdpi,等).这将是伟大的,并可能在某些情况下最小化应用程序大小.

问题

我想就这个新课提出几个问题:

  1. 是否可以在较旧的Android版本中使用它,也许可以通过甚至是Google支持库的库?

  2. 我不熟悉它是如何工作的,但Lollipop可以处理SVG文件吗?它可以做任何可以在SVG文件上实现的东西吗?

  3. 除了我发现的文档之外,是否有使用它的示例/教程/视频?

android vector gradle android-vectordrawable

84
推荐指数
5
解决办法
5万
查看次数

支持库VectorDrawable Resources $ NotFoundException

我使用的是Design Support Library版本23.4.0.我启用了gradle标志:

defaultConfig {
    vectorDrawables.useSupportLibrary = true
}
Run Code Online (Sandbox Code Playgroud)

我正在使用构建工具版本23.0.2,但仍然,我正在Resources$NotFoundException使用KitKat或更低版本.

它发生在我使用android:drawableLeft或时imageView.setImageResource(R.drawable.drawable_image).

是的,我把它放在我使用drawables的每个活动上

static {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
Run Code Online (Sandbox Code Playgroud)

这是支持库的错误吗?

android android-support-library androiddesignsupport android-vectordrawable

67
推荐指数
8
解决办法
3万
查看次数

Android Selector使用VectorDrawables srcCompat绘制

我遇到了与VectorDrawables的新向后兼容性问题.在支持库中,23.2是一个新功能,用于向后兼容所生成的Android VectorDrawables.

我有一个ImageView,它是一个SelectorDrawable分配给.这个Drawable拥有几个VectorDrawables所以我认为我应该使用app:srcCompat来兼容.但它在我的Galaxy S2上使用android 4.1.2不起作用.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_gps_fixed_24dp"android:state_activated="true" android:state_selected="true"></item>
    <item android:drawable="@drawable/ic_gps_not_fixed_24dp" android:state_activated="true" android:state_selected="false"></item>
    <item android:drawable="@drawable/ic_gps_not_fixed_24dp" android:state_activated="false" android:state_selected="true"></item>
    <item android:drawable="@drawable/ic_gps_off_24dp" android:state_activated="false" android:state_selected="false"></item>
    <item android:drawable="@drawable/ic_gps_not_fixed_24dp"></item>
</selector>
Run Code Online (Sandbox Code Playgroud)

所有drawables都是vector xml文件.

当使用此SelectorDrawable与srcCompat时,我收到此错误:

  Caused by: android.content.res.Resources$NotFoundException: File res/drawable/  Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_gps_fixed_24dp.xml from drawable resource ID #0x7f0201c1
                                                                           at android.content.res.Resources.loadDrawable(Resources.java:1951)
                                                                           at android.content.res.Resources.getDrawable(Resources.java:672)
                                                                           at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
                                                                           at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881).xml from drawable resource ID #0x7f0201c1
Run Code Online (Sandbox Code Playgroud)

使用android:src更糟糕.

如果我使用app:srcCompat中的一个矢量drawable,一切正常.所以我猜这是SelectorDrawable和兼容性的问题.

有没有人有同样的问题,并找到了解决方案,或者目前无法在Android 5之前的SelectorDrawables中使用VectorDrawables?

简要说明:

  • 编译目标API 23
  • 支持Libraray 23.3.0
  • vectorDrawables.useSupportLibrary = true
  • Gradle 2.0

android vector android-appcompat android-support-library android-vectordrawable

60
推荐指数
3
解决办法
3万
查看次数

如何为android创建矢量drawable?

我是新来的VectorDrawables.

我可以看到,默认vector drawables提供与Android工作室一样ic_menu_gallery,ic_menu_camera等都是伟大的工作.所以我尝试vector drawables通过将我转换png imagessvg第一个并使用路径和填充值来制作矢量drawables 来创建我自己的东西,即替换svg文件中的android:pathDatafor d和android:fillColorfill标签.它以某种方式给了矢量drawables但扭曲或curlituted看.

如果我没有采取正确的方法,请建议我.

java svg android android-studio android-vectordrawable

50
推荐指数
5
解决办法
8万
查看次数

将VectorDrawable转换为SVG

VectorDrawable手动或使用网络工具进行了相反的转换(SVG ).

但我很难做相反的事情.我有,VectorDrawable但我不知道如何将其转换为SVG,我可以找到零在线工具来做到这一点.

有没有人有这方面的经验,有哪些步骤或工具呢?

svg android android-vectordrawable

48
推荐指数
2
解决办法
3万
查看次数

如何以编程方式将VectorDrawable设置为ImageView的图像

我想在Android Studio 中将一些vectorDrawables设置为ImageView.

我可以轻松设置png和jpg drawable,但是当我想设置VectorDrawable时,它在imageview上不起作用.

img.setImageResource(R.drawable.ic_home);
Run Code Online (Sandbox Code Playgroud)

ic_home是VectorDrawable,此代码不起作用.

android imageview android-vectordrawable

45
推荐指数
4
解决办法
5万
查看次数