Sat*_*r J 2 colors android-actionbar
我的代码是,
\n\n if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {\n Bitmap bm = BitmapFactory.decodeResource(context.getResources(),R.drawable.app_icon);\n ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("AppName", bm ,R.color.colorPrimaryDark);\n setTaskDescription(taskDescription);\n }\nRun Code Online (Sandbox Code Playgroud)\n\n在colors.xml
<color name="colorPrimaryDark">#FF9800</color> \nRun Code Online (Sandbox Code Playgroud)\n\n它给出了错误java.lang.RuntimeException: A TaskDescription\'s primary color should be opaque
编辑1:
\n\n\n\n\n清单文件
\n
<application\n android:allowBackup="true"\n android:icon="@drawable/app_icon3"\n android:label="@string/app_name"\n android:theme="@style/AppTheme">\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n\n样式.xml
\n
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">\n <item name="colorPrimaryDark">#242533</item>\n <item name="colorPrimary">#242533</item>\n <item name="colorAccent">@color/white</item> \n\n</style>\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n\n日志猫
\n
E/AndroidRuntime: FATAL EXCEPTION: main\n Process: co.treeline.kitetrack, PID: 18419\n 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\n at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)\n at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)\n at android.app.ActivityThread.access$900(ActivityThread.java:154)\n at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)\n at android.os.Handler.dispatchMessage(Handler.java:102)\n at android.os.Looper.loop(Looper.java:148)\n at android.app.ActivityThread.main(ActivityThread.java:5443)\n at java.lang.reflect.Method.invoke(Native Method)\n at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)\n at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)\n Caused by: java.lang.RuntimeException: A TaskDescription\'s primary color should be opaque\n at android.app.ActivityManager$TaskDescription.<init>(ActivityManager.java:589)\n at co.treeline.kitetrack.SplashScreen.changeMinimizedActionbarColor(SplashScreen.java:284)\n at co.treeline.kitetrack.SplashScreen.onCreate(SplashScreen.java:73)\n at android.app.Activity.performCreate(Activity.java:6259)\n at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)\n at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)\n at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)\xc2\xa0\n at android.app.ActivityThread.access$900(ActivityThread.java:154)\xc2\xa0\n at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)\xc2\xa0\n at android.os.Handler.dispatchMessage(Handler.java:102)\xc2\xa0\n at android.os.Looper.loop(Looper.java:148)\xc2\xa0\n at android.app.ActivityThread.main(ActivityThread.java:5443)\xc2\xa0\n at java.lang.reflect.Method.invoke(Native Method)\xc2\xa0\n at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)\xc2\xa0\n at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)\xc2\xa0\nRun Code Online (Sandbox Code Playgroud)\n\n这里有什么问题?
\n原因是TaskDescription("AppName", bm ,R.color.colorPrimaryDark)需要颜色值作为参数,并且您正在使用资源 ID。它不一样,你必须通过方法获取你的颜色context.getResources().getColor(R.color.colorPrimaryDark)。
改变 :
ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("AppName", bm ,R.color.colorPrimaryDark);
Run Code Online (Sandbox Code Playgroud)
到
ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("AppName", bm , ContextCompat.getColor(context, R.color.colorPrimaryDark));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4099 次 |
| 最近记录: |