Ich habe Materialdesign in meine App implementiert, und es läuft einwandfrei auf <Android 5, aber wenn ich versuche, auf Android 5.0 oder höher zu laufen, bekomme ich Folgendes in meinem Logcat.
FATAL EXCEPTION main
Process com.test.test, PID 3195
Java.lang.RuntimeException Unable to start activity ComponentInfo{com.test.test/com.test.test.MainActivity} Java.lang.RuntimeException A TaskDescription's primary color should be opaque
at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java2298)
at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java2360)
at Android.app.ActivityThread.access$800(ActivityThread.Java144)
at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java1278)
at Android.os.Handler.dispatchMessage(Handler.Java102)
at Android.os.Looper.loop(Looper.Java135)
at Android.app.ActivityThread.main(ActivityThread.Java5221)
at Java.lang.reflect.Method.invoke(Native Method)
at Java.lang.reflect.Method.invoke(Method.Java372)
at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java899)
at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java694)
Caused by Java.lang.RuntimeException A TaskDescription's primary color should be opaque
at Android.app.ActivityManager$TaskDescription.<init>(ActivityManager.Java536)
at Android.app.Activity.onApplyThemeResource(Activity.Java3677)
at Android.view.ContextThemeWrapper.initializeTheme(ContextThemeWrapper.Java140)
at Android.view.ContextThemeWrapper.setTheme(ContextThemeWrapper.Java85)
at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java2244)
... 10 more
Und hier sind meine Stile:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.NoActionBar">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="colorPrimaryDark">#4DFF9800</item>
<item name="colorPrimary">#4D607D8B</item>
</style>
</resources>
Wenn mir jemand eine Anleitung geben könnte, wäre das ein großer Dank.
Sie können Alfa nicht in der Grundfarbe verwenden. Die Grundfarbe muss undurchsichtig sein.
Veränderung:
<item name="colorPrimaryDark">#4DFF9800</item>
<item name="colorPrimary">#4D607D8B</item>
Zu
<item name="colorPrimaryDark">#FF9800</item>
<item name="colorPrimary">#607D8B</item>
für api 21 in res/values-v21/style.xml
-Datei
@Konrad Krakowiak hat recht.
Sie können den Quellcode von Android.app.ActivityManager # TaskDescription sehen.
/**
* Creates the TaskDescription to the specified values.
*
* @param label A label and description of the current state of this task.
* @param icon An icon that represents the current state of this task.
* @param colorPrimary A color to override the theme's primary color. This color must be opaque.
*/
public TaskDescription(String label, Bitmap icon, int colorPrimary) {
if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
throw new RuntimeException("A TaskDescription's primary color should be opaque");
}
mLabel = label;
mIcon = icon;
mColorPrimary = colorPrimary;
}
Eine einfache Lösung für dieses Problem besteht darin, das in der Farbenfarbe.xml auf die Primärfarbe angewendete Deckmittel zu entfernen
Wenn die Primärfarbe undurchsichtig ist, sieht der Farbcode wie folgt aus: "# aca688ff", wobei es sich dabei um ein Ex handeln muss: "# F50057" (alphanumerischer 6-Buchstaben-Code ohne Deckung).
Hoffen Sie, dass die obige Lösung Ihnen hilft, das Problem zu beheben.