简体   繁体   中英

Cannot Resolve Symbol when importing vector asset in Android Studio

I am using 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

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"
  2. Add this line under defaultConfig in build.gradle(Module:app) - vectorDrawables.useSupportLibrary = "true"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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