gpt4 book ai didi

colors - TaskDescription 的主要颜色应该是不透明的 Android 6.0

转载 作者:行者123 更新时间:2023-12-02 04:02:16 26 4
gpt4 key购买 nike

我的代码是,

 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:TaskDescription的主要颜色应该是不透明的

编辑1:

manifest.xml

<application
android:allowBackup="true"
android:icon="@drawable/app_icon3"
android:label="@string/app_name"
android:theme="@style/AppTheme">

styles.xml

<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>

logcat

 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) 获取颜色。

更改:

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));

关于colors - TaskDescription 的主要颜色应该是不透明的 Android 6.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41298162/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com