Android alpha color issue

I created one application with built-in version 5.0. I have a theme for the topic below.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimaryDark">@color/actionbar_color</item> <item name="colorPrimary">@color/actionbar_color</item> <item name="colorAccent">@color/actionbar_yellow_color</item> <item name="android:windowContentOverlay">@null</item> <item name="android:textColorPrimary">@color/edit_text_color</item> <item name="android:windowBackground">@drawable/ic_app_background</item> </style> 

When I set actionbar_color = "# 4DFFFFFF" My application crashed. If I used any non-alpha color, it works fine, I mean, if I set the color code for actionbar_color = "# FFFFFF ".

Error: the main color of the TaskDescription task should be opaque. I checked this Android 5.0 solution : how to change the overview of the Task Header screen in the background, but got the same error for the alpha color. I follow transparency color hex color transparency

Crash log

  03-20 05: 59: 41.323: E / AndroidRuntime (2133): FATAL EXCEPTION: main
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): Process: com.mytaxback, PID: 2133
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): java.lang.RuntimeException: Unable to start activity ComponentInfo {com.mytaxback / com.mytaxback.LoginActivity}: java.lang.RuntimeException: A TaskDescription primary color should be opaque
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2298)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2360)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at android.app.ActivityThread.access $ 800 (ActivityThread.java:144)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1278)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at android.os.Handler.dispatchMessage (Handler.java:102)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at android.os.Looper.loop (Looper.java:135)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at android.app.ActivityThread.main (ActivityThread.java:5221)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at java.lang.reflect.Method.invoke (Native Method)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at java.lang.reflect.Method.invoke (Method.java data72)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:899)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:694)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): Caused by: java.lang.RuntimeException: A TaskDescription primary color should be opaque
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at android.app.ActivityManager $ TaskDescription. (ActivityManager.java►36)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at android.app.Activity.onApplyThemeResource (Activity.java:3677)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at android.view.ContextThemeWrapper.initializeTheme (ContextThemeWrapper.java:140)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at android.view.ContextThemeWrapper.setTheme (ContextThemeWrapper.java:85)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2244)
 03-20 05: 59: 41.323: E / AndroidRuntime (2133): ... 10 more

I ran into this problem in 5.0 OS emulator. His work works great with ICS, KITKAT Give me any suggestions. Thanks,

+3
android material-design android-theme
source share
3 answers

I assign a background color for the action bar / toolbar and status bar like this, here the color actionbar_color is the alpha color

  mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar); setSupportActionBar(mToolbar); TextView mTitle = (TextView) mToolbar.findViewById(R.id.toolbar_title); mTitle.setText(getString(R.string.login_title)); mTitle.setTypeface(Oswald_Medium); mToolbar.setNavigationIcon(R.drawable.ic_back_arrow); getSupportActionBar().setDisplayShowTitleEnabled(false); mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); mToolbar.setBackgroundColor(getResources().getColor(R.color.actionbar_color)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(getResources().getColor(R.color.actionbar_color)); } 

I noticed that when I write this topic using the eclipse IDE, it causes an error, while the same alpha color works fine in Android Studio. Comment here if you find any better solution on which I wrote this code for Eclipse above, this code is not needed for AndroidStudio

+1
source share

You cannot use alpha in the primary color. You can see the source code of 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; } 
+1
source share

Had the same problem on Lollipop devices, removing the alpha color fixed my problem. Use the link to understand the problem: http://androidxref.com/7.1.1_r6/xref/frameworks/base/core/java/android/app/ActivityManager.java#982

0
source share

All Articles