简体   繁体   中英

Android Studio 1.4.0 Drawable-v21 item ignored in favor of Drawable

I'm having a very similar problem as to what was described in this question, but the answer is hacky and not really a proper answer, although it works.

Android Studio 1.4: drawable-v21 ignored when using "File/New/Vector Asset" option

I have a button, that I want to apply a pressed color to on pre21 devices, and use the ripple on v21+ devices.

In the drawable folder I have button_primary_theme

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape>
            <solid android:color="@color/themePimaryrOnePressed" />

        </shape>
    </item>
    <item>
        <shape>
            <solid android:color="@color/themePrimaryOne" />
        </shape>
    </item>
</selector>

In the drawable-v21 folder I have

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?attr/colorControlHighlight">
    <item android:drawable="?attr/colorPrimary"/>
</ripple>

No matter what I do, I can't get my layout to use the ripple effect from the v21 folder on my Lollipop device. It keeps using the pre lollipop drawable.

<Button
android:id="@+id/getting_started"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_primary_theme" />

In the other answer, he made a separately named file for v21 effect, but that means I need a new copy of the layout in addition to the new drawable, and that shouldn't be necessary to get this to work.

I've tried cleaning the project, but it still uses the non v21 drawable.

How do I get this to work without making copies of everything?

Looks like this was my fault. Hopefully this might help someone else.

My normal drawable was actually in the drawable-nodpi folder, not drawable. I guess that was somehow overriding the v21 folder version.

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