I am using the AppCompat theme and I want set the minHeight attribute on my buttons:
<style name="Theme.MyTheme" parent="Theme.AppCompat">
<item name="android:buttonStyle">@style/MyButtonStyle</item>
</style>
<style name="MyButtonStyle" parent="...?">
<item name="android:minHeight">60dp</item>
</style>
However, there is no Widget.AppCompat.Button
style to set as the parent for MyButtonStyle
. If I use android:Widget.Button
, then all my buttons look like the old crappy style. I tried various other AppCompat themes like TextAppearance.AppCompat.Button
, but they do not work.
Leaving out a parent theme for the button style also causes the button not to be styled correctly.
How can I customize the default Theme.AppCompat
buttonStyle
?
Remove the
android:
https://stackoverflow.com/a/32363833
To answer my own question, it appears AppCompat does not in fact support the
Button
widget presently:The only workaround I see would be to recreate the Material button style from the Android source code, a task which extends outside the scope of my desire.
Custom Button Style With AppCompat +22 in your styles.xml
in your layout.xml
You can have
Base.MyButtonStyle
extendandroid:Widget.Holo.Button
on API 14+ (inres/values-v14/styles.xml
) andandroid:Widget.Material.Button
on API 21+ (inres/values-v21/styles.xml
. This style will change according to the device system version. Put your platform specific modifications here.Then have
MyButtonStyle
extendBase.MyButtonStyle
and define theandroid:minHeight
here (inres/values/styles.xml
). This will apply to all platforms.You buttons then can use style
MyButtonStyle
.This example assumes your minimum SDK is 14.
And yes, there's no appcompat-v7 button style (well, at least not yet).
EDIT
This assumes you're OK with Holo button on platforms older than Lollipop. It feels unobtrusive and if you can do without ripples, it should be just fine. If you want ripples I suggest you google for a third party lollipop button library.