【问题标题】:Android Studio 1.4.0 Drawable-v21 item ignored in favor of DrawableAndroid Studio 1.4.0 Drawable-v21 项目忽略了 Drawable
【发布时间】:2016-02-06 22:38:45
【问题描述】:

我遇到了与这个问题中描述的内容非常相似的问题,但答案很老套,而且不是一个真正正确的答案,尽管它有效。

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

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

在可绘制文件夹中,我有 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 文件夹中的涟漪效果。它继续使用 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" />

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

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

如何在不复制所有内容的情况下使其正常工作?

【问题讨论】:

  • 我首先将两者都移动到它们目录的-nodpi 变体中(res/drawable-nodpi/res/drawable-nodpi-v21/)。仅此一项就可能解决您的问题。
  • 我不确定为什么,但我实际上是在 drawable-nodpi 和 drawable-v21 文件夹中。当我将 drawable-nodpi 移动到 drawable 文件夹中时,它开始正常工作。我已经回答过了。

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-24
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 2021-03-16
    • 1970-01-01
    相关资源
    最近更新 更多