1

I would like to use AppCompat v22 to style my LinearLayout so that it looked like button. I set its style like this:

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

and in app theme I have: colorButtonNormal property set.

After styling LinearLayout looks like button on devices running Lollipop but not on older versions.

Question is - what needs to be set to make LinearLayout look like button on older Android versions too by using AppCompat v22?

questioner
  • 2,283
  • 3
  • 26
  • 35
  • Check out : http://stackoverflow.com/questions/26519979/coloring-buttons-in-android-with-material-design-and-appcompat – Haresh Chhelana May 18 '15 at 05:42
  • @HareshChhelana I think I have different problem. My buttons work fine on all platforms but I want to style LinearLayout (or any other layout) without writing selectors. I want AppCompat to take care of this. – questioner May 18 '15 at 07:32

2 Answers2

0

To customize your LinearLayout set android:theme="@style/AppTheme.Button" in your layout.

<LinearLayout
    ......
    android:theme="@style/AppTheme.Button"
    ......
    />

And define your style

<style name="AppTheme.Button" parent="Base.Widget.AppCompat.Button">
    ........
    <item name="colorButtonNormal">@color/my_color</item>
    ........
</style>
Oleksandr
  • 6,226
  • 1
  • 46
  • 54
  • 1
    You are basically suggesting to use `android:theme` instead of `style`. The outcome is the same: white button-shaped rectangle on Android prior to L. `colorButtonNormal` property is not picked. – questioner Jun 09 '15 at 19:00
0
<LinearLayout
......
android:theme="@style/AppTheme.Button"
......
/>

Define the style:

<style name="AppTheme.Button" parent="Base.Widget.AppCompat.Button">
    ........
    <item name="colorButtonNormal">@color/my_color</item>
    <item name="colorAccent">@color/my_color</item>
    ........
</style>
Gil SH
  • 3,789
  • 1
  • 27
  • 25