?android:attr/selectableItemBackground 需要API等级11(当前最低等级为10)

4
如果我在我的卡片视图上使用这个作为foreground,应用程序在API 10之前的版本上会崩溃。
    <android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:layout_margin="@dimen/card_margin"
 //android:foreground="?android:attr/selectableItemBackground"
    android:elevation="3dp"
    card_view:cardCornerRadius="@dimen/card_album_radius">

我正在开发一个项目已经七个月了,我的应用程序一直可以在所有 API 级别上运行,但现在不行了。这迫使我提高我的最低 SDK 版本要求。
您能帮我解决这个问题吗?如何规避这个问题?

暂时的答案

我正在使用这个方法:

android:foreground="?attr/selectableItemBackground"

代替;而不是。
android:foreground="?android:attr/selectableItemBackground"

这是一种灰色的点击颜色,而不是蓝色,但我并不太在意颜色,所以这暂时解决了崩溃问题。

在build.gradle文件中将最小API级别更改为11。 - Nongthonbam Tonthoi
@DastakWall,你太棒了。 - azizbekian
@DastakWall,你可以通过编程来设置它,但是它仍然会有同样的问题。我不确定,但可能有一些第三方库可以解决这个问题。 - Nongthonbam Tonthoi
至少,如果我在API 10以上以编程方式使用它,应用程序将不会在预先的10上中断。谢谢回复。 - DastakWall
如果你找到答案,就把答案添加到你的问题中。 - Learning Always
显示剩余7条评论
1个回答

0

使用?selectableItemBackgroundBorderless代替?android:attr/selectableItemBackground

使用?attr:(或?的速记)而不是?android:attr来引用支持库,因此可回溯到API 7。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接