我正在尝试通过在活动的XML文件中设置android:background属性来显示CardView触摸时的涟漪效果,如Android开发者页面上这里所述,但它不起作用。没有任何动画,但是onClick方法被调用了。我也尝试像这里建议的创建一个ripple.xml文件,但结果相同。
这是活动的XML文件中CardView的外观:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="155dp"
android:layout_height="230dp"
android:elevation="4dp"
android:translationZ="5dp"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:onClick="showNotices"
android:background="?android:attr/selectableItemBackground"
android:id="@+id/notices_card"
card_view:cardCornerRadius="2dp">
</android.support.v7.widget.CardView>
我对Android开发还比较新,所以可能会犯一些明显的错误。
android:clickable="true"
çڑ„ه·¥ن½œو–¹ه¼ڈم€‚ - Sean?attr/selectableItemBackgroundBorderless
。 - Danylo.Vus