0

I am in a fairly serious predicament. I have built my entire app using ?attr/colorPrimary to pick the color for background shapes, as I have devised a way to dynamically change the theme and color. This works perfectly on 5.0, but on all 4.x devices, ?attr/colorPrimary crashes the app. Why does Android studio not alert developers to this incompatibility?

Is there a support version of ?attr/colorPrimary?

Andrew No
  • 535
  • 6
  • 20
  • i thing you are not use AppCompart library. – Dhaval Parmar Feb 06 '16 at 04:29
  • @dhawalsodhaparmar, initially I had thought the same as I have been working on this for years and even ported it over from eclipse before android studio was a thing. Unfortunately I can assure you I am using it. I will however set up a dummy project and just to see if I can reproduce my crash. Who knows, I'm using support library but maybe something is wrong. – Andrew No Feb 06 '16 at 16:15

4 Answers4

1

colorPrimary is already part of AppCompat as of version 21 and works back to API 7. Your problem is instead with your theming code.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • Strange. Replacing the line with something like @color/color_here stopped the crash, but it does appear to be in the support library. That also explains why android studio does not alert anyone to this issue. Would you happen to have any idea on what the problem could be? I can post any code you need, if it helps. – Andrew No Feb 06 '16 at 16:09
0

I believe it was added after Android Lollipop - API 21.

At least this link shows that it was added between API 20 and 21:

https://developer.android.com/sdk/api_diff/21/changes/android.R.attr.html

attr/colorPrimary just point to colorPrimary defined in current theme.

I'm not sure how you implemented your theme.. But you can create your own attr... This option is good only if you support several themes.

If you have a single theme, I believe you can replace it by a color.

guipivoto
  • 18,327
  • 9
  • 60
  • 75
  • I actually have 15 themes. When I found the issue, I had considered this, but the work that went into being able to dynamically change the theme was too much for me to walk away from. However, I hadn't thought of creating my own attribute. I will play around with that, and I'll let you know the result. – Andrew No Feb 06 '16 at 16:12
0

API 21:

Material design style

Notifications are drawn with dark text atop white (or very light) backgrounds to match the new material design widgets. Make sure that all your notifications look right with the new color scheme. If your notifications look wrong, fix them:

Use setColor() to set an accent color in a circle behind your icon image. Update or remove assets that involve color. The system ignores all non-alpha channels in action icons and in the main notification icon. You should assume that these icons will be alpha-only. The system draws notification icons in white and action icons in dark gray.

0

The problem is a glitch in Android code. See this, it is not the exact same but the reason is.

In case anyone out there has this problem, I want to explain my workaround.

Remove all instances of "?attr/color(Primary, Dark, or Accent)" and attempt to mimic the effect in each individual element in each individual activity. This is not a full work around, but for me it works. Google really needs to resolve this issue. If you know a better work around, please let me know and I will accept it as the better answer as long as it works.

Community
  • 1
  • 1
Andrew No
  • 535
  • 6
  • 20