android - 如何在按钮的另一种样式中使用一种样式?

标签 android button styles

有谁知道如何将样式“MarginButton”添加到样式“bluebutton”或“OrangeButton”?我这样做的原因是为了防止双重代码,这是正确的做法还是有更好的方法来解决这个问题?

<style name="OrangeButton" parent="android:Widget.Button">
    <item name="android:textColor">#000</item>
    <item name="android:background">@drawable/roundedbutton_orange</item>
</style>

<style name="BlueButton" parent="android:Widget.Button">
    <item name="android:textColor">#FFF</item>
    <item name="android:background">@drawable/roundedbutton_blue</item>
</style>

<style name="MarginButton" parent="android:Widget.Button">
    <item name="android:layout_marginTop">10dp</item>
    <item name="android:layout_marginBottom">10dp</item>
    <item name="android:layout_marginLeft">3dp</item>
    <item name="android:layout_marginRight">3dp</item>
</style>

感谢,

乔里斯

最佳答案

更新 将您的橙色按钮父级设置为@style/MarginButton。我刚刚试过这个并且它正在工作,

<style name="orangeButton" parent="@style/MarginButton">
    <item name="android:textColor">#000</item>
    <item name="android:background">@drawable/roundedbutton_orange</item>
</style>

<style name="MarginButton" parent="@android:style/Widget.Button">
    <item name="android:layout_marginTop">10dp</item>
    <item name="android:layout_marginBottom">10dp</item>
    <item name="android:layout_marginLeft">3dp</item>
    <item name="android:layout_marginRight">3dp</item>
</style> 

关于android - 如何在按钮的另一种样式中使用一种样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18056211/

相关文章:

android - Google Play商店并不总是显示当前应用程序版本

android - 线程 sleep 奇怪的行为

android - 如何使用secp256r1类型的椭圆曲线 key 对在Android中加密和解密数据?

html - 如何在固定宽度的 div 中居中动态宽度按钮?

android - 按钮能触发onClick事件吗?

css - 有没有办法在 Angular2 组件内的 ng-content 中使用 css?

android - 无法使用 Purchase.Subscription :acknowledge to acknowledge a subscription

html - 使 Bootstrap 样式覆盖原生 Rails 样式

Sense 手机上的 Android 应用程序主题

wpf - 尝试创建自定义面板但收到 : The object already has a child and cannot add 'Button' compiler exception