2015-04-26 9 views
9

Ich bin Mit com.android.support:appcompat-v7:22.1.1button arbeiten nicht für 22.1.1

Dieses Attribut android:buttonStyle nicht diesen Stil für jede Taste einstellen, muss ich android:theme="@style/AppTheme.Button" manuell auf jeder Taste einzustellen.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="android:buttonStyle">@style/AppTheme.Button</item> 
    </style> 

Was muss ich tun, um einen allgemeinen Stil dafür festzulegen?

+0

welche Version diese Arbeit auf zuletzt getan hat? –

+0

Es funktioniert nicht – Caipivara

+0

Ja, das hast du in deiner Frage gesagt. Hat 'buttonStyle' vorher funktioniert? –

Antwort

17

Verwenden button insteadof android: button in Ihrem Thema

+2

Wann sollte ich 'android:' Attributname verwenden? – Caipivara

+2

@danielgomezrico Von appcompat v21 + sollten Sie sie fallen lassen: http://stackoverflow.com/a/26815521/479478 –

+2

@LenaYan Fehler: (10, 21) Keine Ressource gefunden, die den angegebenen Namen entspricht: Attr 'ButtonStyle'. Welche Ressource sollte hier verwendet werden? Als ursprüngliche Frage Staaten android: buttonStyle funktioniert nicht –

0

Ich landete Einstellung Hintergrundfarbe mit colorButtonNormal Attribut und andere Stilattribute mit buttonStyle.

values/style.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/my_color_primary</item> 
    <item name="colorPrimaryDark">@color/my_color_primary_dark</item> 
    <item name="colorAccent">@color/my_color_accent</item> 
</style> 

<style name="AppTheme.Base"> 
    <item name="colorButtonNormal">@color/my_color_accent</item> 
    <item name="buttonStyle">@style/Button</item> 
</style> 

<style name="Button" parent="Base.Widget.AppCompat.Button"> 
    <item name="android:textColor">@color/my_color_white</item> 
</style> 

values-v21/style.xml

<style name="AppTheme.Base"> 
    <item name="android:colorButtonNormal">@color/my_color_accent</item> 
    <item name="android:buttonStyle">@style/Button</item> 
    </style> 

Und dann alle Tasten haben die Hintergrund-/Textfarbe I ohne Einstellung style auf jeder wollte.

1

Ähnlich @danielgomezrico Antwort, aber ohne zwei Dateien Stil mit:

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 

    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <!-- android:buttonStyle for v21+ and buttonStyle for the rest --> 
    <item name="buttonStyle">@style/MyCustomButton</item> 
    <item name="android:buttonStyle">@style/MyCustomButton</item> 
    <item name="colorButtonNormal">@color/my_color_accent</item> 
</style> 

<style name="MyCustomButton" parent="Base.Widget.AppCompat.Button"> 
    <item name="android:textColor">#ffffff</item> 
</style>