gpt4 book ai didi

android - 将 buttonStyle 用作主题不起作用,但如果直接应用于按钮则可以

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:29:38 24 4
gpt4 key购买 nike

我正在学习关于 creating custom buttons 的教程.如果我直接将样式应用到按钮,它会起作用,但如果我使用 android:buttonStyle 将样式应用到主题,它就不起作用。

示例 - 这是应用了按钮样式的样式 xml:值/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" />

关于我在这里做错了什么的任何指示?

我在 Android 2.3.3 上测试过

来源在github .

最佳答案

试试这个:

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

关于android - 将 buttonStyle 用作主题不起作用,但如果直接应用于按钮则可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8433979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com