dimanche 10 mai 2015

LinearLayout styled as button using AppCompat v22

With AppCompat 22 we can use colorButtonNormal property in app style and then buttons will have selectors based on colour specified in this property. We don't have to write any additional code, any selector ourselves.

I would like to achieve the same behaviour for my LinearLayout which will behave like button (but with more views in it). I set its style like this:

<LinearLayout style="@style/Base.Widget.AppCompat.Button"
....
</LinearLayout>

but colorButtonNormal property is not picked when I run the app on pre-lollipop device. LinearLayout is shaped like button but it's white (default selector for buttons in AppCompat).

I tried setting colorButtonNormal on separate style that extends Base.Widget.AppCompat.Button and assign it to LinearLayout but it still wasn't properly styled.

LinearLayout is styled fine when tested on device running Lollipop.

Is there a way to achieve this via XML?

Aucun commentaire:

Enregistrer un commentaire