安卓按钮默认背景

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

我知道我可以通过使用 custom drawable 来设置我的 buttonbackground,如下所示:

    <?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>

我也知道怎么设置。

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

最佳答案

您可以使用 style="?android:attr/borderlessButtonStyle" 作为按钮的样式。这会给你一个平面风格的外观,也适用于任何前 Lollipop 设备。

引用:http://developer.android.com/reference/android/R.attr.html#borderlessButtonStyle

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

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

关于安卓按钮默认背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30692312/

相关文章:

android - 如何创建弯曲的折叠工具栏布局?

javascript - 如何在 Meteor/React 中打开和关闭 Material-UI 对话框?

android - 如何处理抽屉导航上复选框的 ListView 点击

android - 如何渐变填充按钮的背景?

android - 关于图库 View 的查询

Android布局自定义

android ArrayAdapter 项目更新

android - 如何根据一些特定的分辨率计算分辨率?

javascript - 如何定义 "materializecss"模态 "before"(加载前)功能

javascript - 如何覆盖(overwrite)material-ui(React)中的类和样式