简体   繁体   English

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

[英]Cannot Resolve Symbol when importing vector asset in Android Studio

I am using AS 1.5.1我正在使用 AS 1.5.1

So I tried to import a vector asset by following this:所以我尝试通过以下方式导入矢量资产:

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

I tried to use my drawable like this:我试图像这样使用我的可绘制对象:

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

However, it was highlighted red and telling me that cannot resolve symbol.但是,它以红色突出显示并告诉我无法解析符号。

Why is that so?为什么?

This is my whole layout file:这是我的整个布局文件:

    <?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>

This is my drawable structure.这是我的可绘制结构。 在此处输入图像描述

thanks!谢谢!

Just follow these steps:只需按照以下步骤操作:

  1. Change app:src="@android:drawable/xyz" to app:srcCompat="@drawable/xyz"app:src="@android:drawable/xyz"更改为app:srcCompat="@drawable/xyz"
  2. Add this line under defaultConfig in build.gradle(Module:app) - vectorDrawables.useSupportLibrary = "true"在 build.gradle(Module:app) 中的 defaultConfig下添加这一行 - vectorDrawables.useSupportLibrary = "true"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM