android - 使用混淆器混淆后,CardView 阴影未出现在 Lollipop 中

标签 android proguard android-cardview

应用 Proguard 后,我的 CardView 的阴影在 Lollipop 设备上消失了。我没有定义任何规则来保护这个库,因为我还没有读到它是必要的。

我附上了几个屏幕截图,第一个是未运行 proguard 的,第二个是运行后的。

Screenshot without proguard

Screenshot with proguard

这是我的xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingBottom="@dimen/activity_vertical_margin"
            tools:context=".MainActivity">

    <android.support.v7.widget.CardView
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_margin="4dp"
        app:contentPadding="10dp"
        app:cardUseCompatPadding="true">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text 1"/>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_margin="4dp"
        app:contentPadding="10dp"
        app:cardUseCompatPadding="false">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text 2"/>
    </android.support.v7.widget.CardView>

</LinearLayout>

Activity 仅将 xml 设置为内容,仅此而已。 如您所见,我正在使用 cardUseCompatPadding 的两种可能性,但它并没有解决 this thread 中定义的问题。 .

有人知道为什么 proguard 会破坏我的影子吗?

最佳答案

在深入了解库包之后,我编写了一条规则来保护 android.support.** 中的所有内容,现在我终于只保护 android.support.v7.widget.RoundRectDrawable。

因此,如果您遇到问题,只需在混淆器配置中添加下一条规则:

-keep class android.support.v7.widget.RoundRectDrawable { *; }

关于android - 使用混淆器混淆后,CardView 阴影未出现在 Lollipop 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29679177/

相关文章:

java - 在带有 proguard 的 Android 生产代码中使用 Hamcrest Matchers 时出现运行时错误

android - 在 Android 5.0 上的 AppCompat CardView 上以 XML 设置海拔

android - 将图像放置在卡片 View 中时不显示图像

android - 以编程方式实现RadioButton的不同文本大小

android - 动态添加 fragment 时出错 -java.lang.IllegalStateException :

java - 如何使用Firestore向文档中的 HashMap 数组添加数据?

android - 如何在没有php的情况下在android中使用java使用volley检索mysql数据?

java - Dexguard 在 Ant 调试构建期间运行?

android - Proguard 与 Parceler 和 Realm

android - ListView 根本不可见