【问题标题】:Android button default backgroundAndroid 按钮默认背景
【发布时间】:2015-06-07 10:08:24
【问题描述】:

我知道我可以像这样使用custom drawable 来设置button 的background:

    <?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true" >
        <shape>
            <gradient
                android:startColor="#ffffff"
                android:endColor="#ffffff"
                android:angle="270" />
        </shape>
    </item>

    <item android:state_focused="true" >
        <shape>
            <gradient
                android:endColor="#ffffff"
                android:startColor="#ffffff"
                android:angle="270" />
        </shape>
    </item>

    <item>        
        <shape>
            <gradient
                android:endColor="#ffffff"
                android:startColor="#ffffff"
                android:angle="270" />
        </shape>
    </item>
</selector>

我也知道怎么设置。

但我真正的问题是:如何让默认材料设计按钮的外观和感觉只有不同的颜色,我似乎无法在 Android 源代码中找到它的默认样式。

【问题讨论】:

标签: android android-layout material-design android-styles


【解决方案1】:

您可以使用style="?android:attr/borderlessButtonStyle" 作为按钮的样式。这将为您提供扁平风格的外观,并且也适用于任何棒棒糖之前的设备。

参考:http://developer.android.com/reference/android/R.attr.html#borderlessButtonStyle

如果您对向后可压缩性不感兴趣,则可以使用 Raised Button,它具有涟漪效应并且需要运行 5.0 的设备

<style name="Your.Button" parent="android:style/Widget.Material.Button">
    <item name="android:background">@drawable/raised_background</item>
</style>

raised_background.xml

    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="?attr/colorControlHighlight">
        <item android:drawable="@color/button_color"/>
    </ripple>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-26
    • 2018-10-13
    • 2014-11-03
    • 1970-01-01
    • 2017-11-05
    • 2012-05-21
    • 2018-08-03
    • 1970-01-01
    相关资源
    最近更新 更多