Android材料设计按钮 - 前棒棒糖

ric*_*ert 75 android button material-design

如何实施谷歌材料设计指南中描述的"凸起按钮"和"平面按钮"?


凸起的按钮为大多数平面布局增加了尺寸.他们强调繁忙或宽阔空间的功能.

凸起的按钮


使用工具栏和对话框的平面按钮可避免过度分层.

平面按钮

资料来源:http://www.google.com/design/spec/components/buttons.html

Gab*_*iel 121

这需要Android 5.0

凸起的按钮

从Widget.Material.Button继承您的按钮样式,将自动应用标准的提升和提升操作.

<style name="Your.Button" parent="android:style/Widget.Material.Button">
    <item name="android:background">@drawable/raised_button_background</item>
</style>
Run Code Online (Sandbox Code Playgroud)

然后,您需要raised_button_background.xml在波纹标记内创建一个带有按钮背景颜色的文件:

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?attr/colorControlHighlight">
    <item android:drawable="@color/button_color"/>
</ripple>
Run Code Online (Sandbox Code Playgroud)

平面按钮

编辑:您应该遵循Stephen Kaiser给出的建议,而不是我以前对平面按钮的建议:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="DONE"
    style="?android:attr/borderlessButtonStyle"
/>
Run Code Online (Sandbox Code Playgroud)

编辑:如果您使用支持库,则可以使用在Pre-Lollipop设备上获得相同的结果style="?attr/borderlessButtonStyle".(注意没有android:)上面的例子就变成了

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="DONE"
    style="?attr/borderlessButtonStyle"
/>
Run Code Online (Sandbox Code Playgroud)

  • 任何使凸起按钮样式在棒棒糖前工作的方法?即使是假风格? (3认同)
  • 禁用/启用状态看起来相同.如何解决? (2认同)
  • 使用材料设计时,为什么扁平(无边框)按钮不会拉出强调色样式?最好使用buttonBarButtonStyle? (2认同)

Ste*_*ser 84

为了实现平面按钮,您可以添加style="?android:attr/borderlessButtonStyle".

例:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="DONE"
    style="?android:attr/borderlessButtonStyle"
    />
Run Code Online (Sandbox Code Playgroud)

这是属性的参考.

  • `style ="@ style/Widget.AppCompat.Button.Borderless"`使用AppCompat库时 (4认同)
  • 太棒了,它支持API级别11. (3认同)
  • 但是前棒棒糖设备的风格不同 (2认同)