本文介绍了TaskDescription的原色应为不透明的Android 6.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Bitmap bm = BitmapFactory.decodeResource(context.getResources(),R.drawable.app_icon);
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("AppName", bm ,R.color.colorPrimaryDark);
        setTaskDescription(taskDescription);
    }

colors.xml

<color name="colorPrimaryDark">#FF9800</color> 

它给出错误java.lang.RuntimeException: A TaskDescription's primary color should be opaque

<application
    android:allowBackup="true"
    android:icon="@drawable/app_icon3"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimaryDark">#242533</item>
    <item name="colorPrimary">#242533</item>
    <item name="colorAccent">@color/white</item>                    

</style>
 E/AndroidRuntime: FATAL EXCEPTION: main
              Process: co.treeline.kitetrack, PID: 18419
              java.lang.RuntimeException: Unable to start activity ComponentInfo{co.treeline.kitetrack/co.treeline.kitetrack.SplashScreen}: java.lang.RuntimeException: A TaskDescription's primary color should be opaque
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
                  at android.app.ActivityThread.access$900(ActivityThread.java:154)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:148)
                  at android.app.ActivityThread.main(ActivityThread.java:5443)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
               Caused by: java.lang.RuntimeException: A TaskDescription's primary color should be opaque
                  at android.app.ActivityManager$TaskDescription.<init>(ActivityManager.java:589)
                  at co.treeline.kitetrack.SplashScreen.changeMinimizedActionbarColor(SplashScreen.java:284)
                  at co.treeline.kitetrack.SplashScreen.onCreate(SplashScreen.java:73)
                  at android.app.Activity.performCreate(Activity.java:6259)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
                  at android.app.ActivityThread.access$900(ActivityThread.java:154) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:148) 
                  at android.app.ActivityThread.main(ActivityThread.java:5443) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 

这是什么问题?

推荐答案

原因是TaskDescription("AppName", bm ,R.color.colorPrimaryDark)需要颜色值作为参数,而您正在使用资源ID.情况不同,您必须通过方法context.getResources().getColor(R.color.colorPrimaryDark)来获取颜色.

The reason is that TaskDescription("AppName", bm ,R.color.colorPrimaryDark) needs colour value as parameter and you're using resource id. It is not the same, you have to get your colour via method context.getResources().getColor(R.color.colorPrimaryDark).

更改:

ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("AppName", bm ,R.color.colorPrimaryDark);

ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("AppName", bm , ContextCompat.getColor(context, R.color.colorPrimaryDark));

这篇关于TaskDescription的原色应为不透明的Android 6.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 04:57