2011-12-08 7 views
6

Podążałem za tutorialem na temat creating custom buttons. Jeśli zastosuję styl do przycisku bezpośrednio, to działa, ale jeśli zastosuję ten styl do motywu przy użyciu android:buttonStyle, to nie działa.Stosowanie przycisku buttonStyle jako kompozycji nie działa, ale ma zastosowanie do przycisku bezpośrednio

Przykładem - Oto xml styl przyciskiem stylu zastosowano: wartości/styles.xml

<resources> 
    <style name="MyTheme" parent="android:Theme.Light"> 
     <!-- the button gets styled but is no longer clickable 
      if i do it like this --> 
     <item name="android:buttonStyle">@style/ButtonText</item> 
    </style> 

    <style name="ButtonText"> 
     <item name="android:layout_width">fill_parent</item> 
     <item name="android:layout_height">wrap_content</item> 
     <item name="android:textColor">#ffffff</item> 
     <item name="android:background">@drawable/ruddy_orange_button</item> 
    </style> 
</resources> 

odkształcalne/ruddy_orange_button.xml:

<item android:state_pressed="true"> 
     <shape> 
      <solid android:color="#70c656" /> 
      <stroke android:width="1dp" android:color="#53933f" /> 
      <corners android:radius="3dp" /> 
      <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> 
     </shape> 
    </item> 
    <item> 
     <shape> 
      <gradient android:angle="270" android:endColor="#fd4d4d" android:startColor="#f24b4b" /> 
      <stroke android:width="1dp" android:color="#f04a4a" /> 
      <corners android:radius="4dp" /> 
      <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> 
     </shape> 
    </item> 
</selector> 

Jednak jeśli mogę ubiegać styl bezpośrednio do przycisku, który działa:

<Button 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    style="@style/ButtonText" 
    android:text="hello there" /> 

Jakieś wskazówki na temat tego, co robię źle tutaj?

Przetestowałem to na Androidzie 2.3.3

źródłowy jest github.

Odpowiedz

9

Spróbuj tego:

<style name="ButtonText" parent="@android:style/Widget.Button"> 
6

miałem również ten problem.hope końcówka pomoże Ci

AppCompat V21 + należy użyć buttonStyle zamiast android:buttonStyle w temacie

Powiązane problemy