android - CardView 在前 Lollipop 设备中显示黑色(不太好看)阴影

标签 android xml android-layout android-studio android-cardview

卡片浏览 Lollipop 前设备在长按或单击通常会在具有 Lollipop 或更高版本的设备中显示波纹的位置时显示难看的黑色渐变。

cardview ugly pre-lollipop

这是我的 CardView XML

<android.support.v7.widget.CardView
    android:id="@+id/cardview1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    style="@style/swipe_section_padding"
    android:foreground="?android:attr/selectableItemBackground"
    android:clickable="true"
    card_view:cardCornerRadius="3dp"
    card_view:cardElevation="0dp"
    card_view:contentPadding="0dp">

    <RelativeLayout ...
 </android.support.v7.widget.CardView>

最佳答案

尝试添加 card_view:cardUseCompatPadding="false"属性,

useCompatPadding boolean: true> if CardView should add padding for the shadows on platforms Lollipop and above.



查看cardview:cardUseCompatPadding
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dip" >

    <android.support.v7.widget.CardView
        android:id="@+id/cardview1"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:clickable="true"
        android:foreground="?android:attr/selectableItemBackground"
        card_view:cardCornerRadius="3dp"
        card_view:cardElevation="2dp"
        card_view:cardUseCompatPadding="false"
        card_view:contentPadding="0dp" >
    </android.support.v7.widget.CardView >
</LinearLayout >

关于android - CardView 在前 Lollipop 设备中显示黑色(不太好看)阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37387830/

相关文章:

android - 如何在从 LinearLayout 中删除第二个 cardview 时向第一个 cardview 添加 Add_button,即当线性布局中要留下的子项数量是?

android - 更新 TextView 的文本导致 GC_CONCURRENT 问题

java - Android 发送自定义电子邮件 STARTTLS 端口 587

Android 12 - Material You 图标

php - 从 mysql 服务器加载的文本没有出现在 ListView 中

android - 向 View 添加自定义属性

java - 使用 xsi :nil and attributes in .Net/Jaxb 创建 XML 元素

java - XML 解析出现细微错误?

php - 如何将数组内部指针设置到特定位置? PHP/XML

android - 在横向模式下支持不同的屏幕尺寸