6

カスタムボタンの作成に関するチュートリアルに従っていました。ボタンに直接スタイルを適用すると機能しますが、それを使用してテーマにスタイルを適用するandroid:buttonStyleと機能しません。

例-ボタンスタイルが適用されたスタイルxmlは次のとおりです:values / 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>

drawable / 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>

ただし、スタイルをボタンに直接適用すると、機能します。

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

私がここで間違っていることについてのポインタはありますか?

これをAndroid2.3.3でテストしました

ソースはgithubにあります。

4

2 に答える 2

9

これを試して:

<style name="ButtonText" parent="@android:style/Widget.Button">
于 2011-12-08T16:19:56.370 に答える
6

私もこの問題を抱えていました。ヒントがあなたを助けることを願っています

テーマbuttonStyleの代わりに使用する必要があるappcompatv21+android:buttonStyle

于 2015-07-30T11:09:54.967 に答える