Cícero Moura
Cícero Moura

Reputation: 2333

Theme with colorAcent (material support appcompat) not apply in custom widgets

I have a MyCheckBox that extends from CheckBox.

I set a color in colorAcent attribute, in the theme of my application.

I noticed that every checkbox that is MyCheckBox gets black icon, but if I declare a native CheckBox he gets the color defined in colorAcent.

Do you know why?

Upvotes: 1

Views: 566

Answers (2)

Sylfo
Sylfo

Reputation: 667

Qianqian is right, this is a known limitation. The support library actually monitors when layouts are inflated and substitutes the original widget implementations by the support equivalents. However, this only works for standard widgets…

You can still workaround this limitation by inheriting your custom components directly from the support library version. The procedure is described in this post but, beware, the class names have changed !

Now, for example, you would have to extend AppCompatSpinner rather than Spinner (TintSpinner does not exist any more in support library).

Upvotes: 0

Qianqian
Qianqian

Reputation: 2124

This is a known limitation in the AppCompat v7 support library. See the FAQ in this Android Developer blog post.

Basically you have to use the system Widgets in XML inflation if you wish to use the tint feature of the supported widgets.

Upvotes: 3

Related Questions