Android Studio 1.4.0 Drawable-v21 项被忽略以支持 Drawable

标签 android android-layout android-animation android-5.0-lollipop

关于这个问题中描述的内容,我遇到了一个非常相似的问题,但答案是 hacky 并且不是一个真正正确的答案,尽管它有效。

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

我有一个按钮,我想在 pre21 设备上应用按下的颜色,并在 v21+ 设备上使用波纹。

在 drawable 文件夹中我有 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>

在我的drawable-v21文件夹中

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

无论我做什么,我都无法让我的布局使用 Lollipop 设备上 v21 文件夹中的涟漪效果。它继续使用 Lollipop 之前的可绘制对象。

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

在另一个答案中,他为 v21 效果制作了一个单独命名的文件,但这意味着除了新的可绘制对象之外,我还需要布局的一个新副本,这不是让它工作所必需的。

我已经尝试清理项目,但它仍然使用非 v21 可绘制对象。

如何在不复制所有内容的情况下让它工作?

最佳答案

看来这是我的错。希望这可能对其他人有所帮助。

我的普通drawable实际上在drawable-nodpi文件夹中,不是drawable。我猜这是以某种方式覆盖了 v21 文件夹版本。

关于Android Studio 1.4.0 Drawable-v21 项被忽略以支持 Drawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33555670/

相关文章:

Android:顺序绘图不删除之前绘制的

android - 从 Activity 外部调用 findViewById()

java - 自定义布局中 switchpreference 中开/关切换的颜色变化

android - TableRow 高度不会根据 android TableLayout 中的内容增加吗?

android - Google 的 Android 应用颜色工具

android - 如何使 TextView 闪烁

android - GridView 3 Columns/GridView 1 Column 之间的动画

Android SQLite 数据库 : Creating db at runtime or using prepopulated db?

android - 在屏幕方向更改时取消绑定(bind) onDestroy 中的远程服务

Android 将 unicode 字符串设置为 textview