在Android Studio中导入矢量资产时无法解析符号

问题描述 投票:2回答:1

我使用的是AS 1.5.1

所以我尝试通过以下方式导入矢量资产:

http://developer.android.com/tools/help/vector-asset-studio.html

我试着像这样使用我的drawable:

android:src="@android:drawable/ic_av_timer_24dp.xml"

然而,它突出显示为红色并告诉我无法解析符号。

为什么会这样?

这是我的整个布局文件:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="org.isg.shinobi.isg.MainActivity"
    android:id="@+id/coordinator">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />



    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </FrameLayout>


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_av_timer_24dp.xml" />

</android.support.design.widget.CoordinatorLayout>

这是我的可绘制结构。 enter image description here

谢谢!

android
1个回答
0
投票

只需按以下步骤操作: 1.将app:src =“@ android:drawable / xyz”更改为app:srcCompat =“@ drawable / xyz” 2.在build.gradle(Module:app)中的defaultConfig下添加此行 - “vectorDrawables.useSupportLibrary = true”

© www.soinside.com 2019 - 2024. All rights reserved.