我为项目使用不同的主题(5种不同的颜色)。我为可绘制的背景项创建了一个xml文件,这个背景项必须有相应的主题颜色。程序明星时我得到一个例外:
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
-keepclasseswithmembernames public class
com.leadsquared.app.helpers.HttpRequest{
public protected private *;
}
-keepclassmembers public class com.leadsquared.app.models.**{
<fields>;
}
-keep class com.leadsquared.app.fragments.LeadListFragment$* {*;}
-keep class com.leadsquared.app.globals.**{ *; }
-keepattributes *Annotation*,Signature
-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
-keep class android.support.v7.widget.SearchView { *; }
-dontwarn android.support.v4.**
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class android.support.v4.** { *; }
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembers class * {
}
-keep class org.apache.http.** { *; }
-keep class org.apache.commons.** { *; }
-keepclassmembers enum * { *; }
-dontwarn org.apache.http.*
#-keep class com.uservoice.uservoicesdk.**{*;}
#-keep class com.uservoice.uservoicesdk.rest.**{*;}
-keep class sun.misc.Unsafe { *; }
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
-keep class com.google.code.gson.stream.** { *; }
-keep class com.google.code.gson.examples.android.model.** { *; }
-keepattributes SourceFile,LineNumberTable
-dontwarn com.mixpanel.**
-keep class com.mixpanel.android.mpmetrics.** { *; }
-dontwarn com.mixpanel.android.mpmetrics.**
-dontwarn java.nio.file.Files
-dontwarn java.nio.file.Path
-dontwarn java.nio.file.OpenOption
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-ignorewarnings
-keep class * {
public private *;
}
/drawable/badge_background.xml文件:
android.view.InflateException: Binary XML file line #14: Error inflating class TextView
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/badge_background.xml from drawable resource ID #0x7f020061
AndroidStudio不会对此问题提供任何错误或警告。它只是完美编译,但我在运行时得到了异常。并且colorPrimaryDark在我的所有主题中定义。
如何克服这个问题?
编辑:有些人一直在问为什么你不使用colorPrimaryDarkRed。因为它应该具有“主题的颜色”,而不是一直是红色。这是我的styles.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:useLevel="false"
android:thickness="10dp"
android:innerRadius="0dp">
<solid
android:color="#444" />
<stroke
android:width="2dp"
android:color="?colorPrimaryDark" />
<padding
android:top="5dp"
android:bottom="5dp"/>
</shape>
EDIT2:badge_cart_layout.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimaryRed</item>
<item name="colorPrimaryDark">@color/colorPrimaryDarkRed</item>
<item name="colorAccent">@color/colorAccentRed</item>
</style>
<style name="AppThemeBlue" parent="AppTheme" >
<item name="colorPrimary">@color/blue</item>
<item name="colorPrimaryDark">@color/blue</item>
</style>
答案 0 :(得分:0)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:useLevel="false"
android:thickness="10dp"
android:innerRadius="0dp">
<solid
android:color="#444" />
<stroke
android:width="2dp"
android:color="@color/colorPrimaryDark" />
<padding
android:top="5dp"
android:bottom="5dp"/>
</shape>
注意:试试这个