简体   繁体   中英

Android Studio Resource Manager vector drawable preview

I have a lot of vector drawables in my project. All of them are being used a fillColor as a theme attribute. In this case, the Resource Manager preview is not being shown until set some color by tools to a drawable.

在此处输入图片说明

As you can see in the picture, ic_drag is red because of tools:fillColor="#ff0000". But the ic_arrow_back_on_primary preview is empty.

ic_drag:

 <vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:width="24dp"
    android:height="24dp"
    android:tint="?attr/colorControlNormal"
    android:viewportWidth="24"
    android:viewportHeight="24">
    <path
        android:fillColor="?banan"
        tools:fillColor="#ff0000"
        android:pathData="M20,9H4v2h16V9zM4,15h16v-2H4V15z" />
</vector>

ic_arrow_back_on_primary:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:tint="?attr/colorControlNormal"
    android:viewportWidth="24"
    android:viewportHeight="24">
    <path
        android:fillColor="?colorOnPrimary"
        android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
</vector>

If open the drawable's editor, a preview is being shown for this drawable. Doesn't matter which way to use: attribute or direct color.

在此处输入图片说明

Is there any way to force the Resource Manager to show preview without adding "tools" attr?

For Android Studio to render that preview, it needs to know what color(s) to use.

In the case of ic_arrow_back_on_primary , both the android:tint attr and the android:fillColor attr are using theme attributes (anything that starts with a ? ). Theme attributes are, of course, dependent on the theme currently in use, and the resource manager doesn't (seem to) have a way to specify the theme to use for the previews.

So, no, there's no way to get the previews to display without adding a tools attribute, unless you are willing to use colors that aren't dependent on the current theme (which may not be viable for your use cases).

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