5.1 Crash - Основной цвет задачи TaskDescription должен быть непрозрачным
Я внедрил материальный дизайн в свое приложение, и он отлично работает на < Android 5, но когда я пытаюсь запустить на Android 5.0 и выше, я получаю следующее в своем 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 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 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
И вот мои стили:
<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>
Если бы кто-нибудь мог дать мне несколько советов, которые были бы очень благодарны.
Ответы
Ответ 1
Вы не можете использовать альфа в основном цвете. Основной цвет должен быть непрозрачным.
Изменить:
<item name="colorPrimaryDark">#4DFF9800</item>
<item name="colorPrimary">#4D607D8B</item>
Для
<item name="colorPrimaryDark">#FF9800</item>
<item name="colorPrimary">#607D8B</item>
для api 21 в res/values-v21/style.xml
файле
Ответ 2
@Konrad Krakowiak прав.
Вы можете увидеть исходный код android.app.ActivityManager # TaskDescription.
/**
* 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 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 primary color should be opaque");
}
mLabel = label;
mIcon = icon;
mColorPrimary = colorPrimary;
}
Ответ 3
Простое решение проблемы - удалить непрозрачный, примененный к основному цвету в цветах .xml
Когда непрозрачный применяется к основному цвету, цветовой код выглядит как "# aca688ff", где он должен быть ex: "# F50057" (буквенно-цифровой код букв без непрозрачности).
Надеемся, что вышеупомянутое решение поможет вам решить проблему.