Bhavin Chauhan
Bhavin Chauhan

Reputation: 2010

Android material theme alpha color issue

I have create one app with build version 5.0 I have write theme 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 app is crashed. If I used any non alpha color it's works fine I mean If I set color code for actionbar_color="#FFFFFF" Its works fine.

Error is :A TaskDescription's primary color should be opaque I have checked this solution Android 5.0: howto change Overview Screen Task Title background color but got same error for alpha color. I have follow this for opacity color Hex transparency in colors

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's 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:372)
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's primary color should be opaque
03-20 05:59:41.323: E/AndroidRuntime(2133):     at android.app.ActivityManager$TaskDescription.(ActivityManager.java:536)
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 faced this issue in 5.0 OS emulator. Its works fine with ICS, KITKAT Give me any suggetions. Thanks,

Upvotes: 4

Views: 4125

Answers (3)

Saggy
Saggy

Reputation: 465

Had a same problem on Lollipop devices, removing alpha color fixed my issue.Use reference this link for understanding issue : http://androidxref.com/7.1.1_r6/xref/frameworks/base/core/java/android/app/ActivityManager.java#982

Upvotes: 0

Jimson
Jimson

Reputation: 211

You can not use alfa in 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's 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's primary color should be opaque");
      }

      mLabel = label;
      mIcon = icon;
      mColorPrimary = colorPrimary;
    }

Upvotes: 1

Bhavin Chauhan
Bhavin Chauhan

Reputation: 2010

I have assign background color for actionbar/toolbar and status bar like this, Here actionbar_color color is 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 have noticed that when I write this theme using eclipse IDE it cause an error while same alpha color run fine in Android Studio. Please comment here if you find out any better solution I have wrote this above code for Eclipse, no need this code for AndroidStudio

Upvotes: 1

Related Questions