在最新的 Android SDK 中,我们现在有了新的 CardView,我已经用新版本替换了旧的 CustomCardView,但是在旧版本的 Android 上运行时,我看到state_pressed
&state_focused
是出现在 CardView 上方的丑陋方块...
有谁知道我如何在新的 CardView 中模拟以下内容,但仅在使用旧版本的 Android 时?
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:enterFadeDuration="150"
android:exitFadeDuration="150" >
<item android:state_pressed="true"
android:drawable="@drawable/card_on_press"/>
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/card_on_focus"/>
<item android:state_enabled="true"
android:drawable="@drawable/card_default"/>
<item android:state_enabled="false"
android:drawable="@drawable/card_on_press"/>
</selector>
对于那些对这里感兴趣的人,我现在正在使用 CardView:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:foreground="?android:attr/selectableItemBackground"
android:onClick="RunSomeMethod"
card_view:cardCornerRadius="4dp"
android:focusable="true"
android:elevation="2dp">
<LinearLayout
android:id="@+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:focusable="false"
android:visibility="visible">
</LinearLayout>
</android.support.v7.widget.CardView>