本文翻译自:Android Material Design Button Styles

I'm confused on button styles for material design. 我对材质设计的按钮样式感到困惑。 I'd like to get colorful raised buttons like in the attached link., like the "force stop" and "uninstall" buttons seen under the usage section. 我想获得彩色的凸起按钮,如附件链接中所示。例如,在“使用情况”部分下看到的“强制停止”和“卸载”按钮。 Are there available styles or do I need to define them? 是否有可用的样式或需要定义它们?

http://www.google.com/design/spec/components/buttons.html#buttons-usage http://www.google.com/design/spec/components/buttons.html#buttons-usage

I couldn't find the default button styles. 我找不到默认的按钮样式。

Example: 例:

 <Button style="@style/PrimaryButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Calculate"android:id="@+id/button3"android:layout_below="@+id/editText5"android:layout_alignEnd="@+id/editText5"android:enabled="true" />

If I try to change the background color of the button by adding 如果我尝试通过添加来更改按钮的背景色

    android:background="@color/primary"

all of the styles go away, such as the touch animation, shadow, rounded corner, etc. 所有样式都会消失,例如触摸动画,阴影,圆角等。


#1楼

参考:https://stackoom.com/question/1mXzD/Android-Material-Design按钮样式


#2楼

you can give aviation to the view by adding z axis to it and can have default shadow to it. 您可以通过向其添加z轴来为视图提供航空功能,并为其具有默认阴影。 this feature was provided in L preview and will be available after it release. 此功能在L预览中提供,并且在发布后将可用。 For now you can simply add a image the gives this look for button background 现在,您只需添加图像即可使按钮背景看起来像这样


#3楼

Here is how I got what I wanted. 这就是我想要的方式。

First, made a button (in styles.xml ): 首先,制作一个按钮(在styles.xml ):

<style name="Button"><item name="android:textColor">@color/white</item><item name="android:padding">0dp</item><item name="android:minWidth">88dp</item><item name="android:minHeight">36dp</item><item name="android:layout_margin">3dp</item><item name="android:elevation">1dp</item><item name="android:translationZ">1dp</item><item name="android:background">@drawable/primary_round</item>
</style>

The ripple and background for the button, as a drawable primary_round.xml : 按钮的波纹和背景,作为可绘制的primary_round.xml

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/primary_600"><item><shape xmlns:android="http://schemas.android.com/apk/res/android"><corners android:radius="1dp" /><solid android:color="@color/primary" /></shape></item>
</ripple>

This added the ripple effect I was looking for. 这增加了我一直在寻找的涟漪效应。


#4楼

If I understand you correctly, you want to do something like this: 如果我对您的理解正确,那么您想要执行以下操作:

In such case, it should be just enough to use: 在这种情况下,使用它就足够了:

<item name="android:colorButtonNormal">#2196f3</item>

Or for API less than 21: 或对于少于21的API:

<item name="colorButtonNormal">#2196f3</item>

In addition to Using Material Theme Tutorial . 除了使用Material Theme教程 。

Animated variant is here . 动画变体在这里 。


#5楼

Here is a sample that will help in applying button style consistently across your app. 这是一个示例,有助于在应用程序中一致地应用按钮样式。

Here is a sample Theme I used with the specific styles.. 这是我与特定样式一起使用的示例主题。

<style name="MyTheme" parent="@style/Theme.AppCompat.Light"><item name="colorPrimary">@color/primary</item><item name="colorPrimaryDark">@color/primary_dark</item><item name="colorAccent">@color/accent</item><item name="android:buttonStyle">@style/ButtonAppTheme</item>
</style>
<style name="ButtonAppTheme" parent="android:Widget.Material.Button">
<item name="android:background">@drawable/material_button</item>
</style>

This is how I defined the button shape & effects inside res/drawable-v21 folder... 这就是我在res / drawable-v21文件夹中定义按钮形状和效果的方式...

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"android:color="?attr/colorControlHighlight"><item><shape xmlns:android="http://schemas.android.com/apk/res/android"><corners android:radius="2dp" /> <solid android:color="@color/primary" /></shape></item>
</ripple>

2dp corners are to keep it consistent with Material theme. 2dp角落将使其与Material主题保持一致。


#6楼

I've just created an android library, that allows you to easily modify the button color and the ripple color 我刚刚创建了一个android库,可让您轻松修改按钮颜色和波纹颜色

https://github.com/xgc1986/RippleButton https://github.com/xgc1986/RippleButton

<com.xgc1986.ripplebutton.widget.RippleButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/btn"android:text="Android button modified in layout"android:textColor="@android:color/white"app:buttonColor="@android:color/black"app:rippleColor="@android:color/white"/>

You don't need to create an style for every button you want wit a different color, allowing you to customize the colors randomly 您无需为要使用不同颜色的每个按钮创建样式,即可随意自定义颜色

Android Material Design按钮样式相关推荐

  1. Android Material Design按钮样式设计

    Today we'll dive deep into Android Buttons in Material Design and develop an application that showca ...

  2. android夜间模式揭露动画,Android Material Design系列之夜间模式

    今天我们讲讲夜间模式的实现,这篇文章的名字应该叫:<Android Material Design系列之夜间模式>.在Android 5.0 之后,实现夜间模式并非很难了,支持的5.0库提 ...

  3. Android Material Design简单使用 http://www.cnblogs.com/android-blogs/p/5632103.html

    Android Material Design简单使用 吐槽 作为一个 Android developer,没有什么比拿着 UI 设计的一堆 iOS 风格的设计 来做需求更恶心的了,基本所有空间都要照 ...

  4. Android Material Design 系列之 BottomNavigationView + ViewPager + Fragment + BadgeView 开发详解

    前言 BottomNavigationView 是 Material Design 提供的一个标准底部导航栏的实现,可以轻松的实现导航栏菜单之间的切换与浏览.底部导航使用户更方便的查看和切换最高层级的 ...

  5. 值得一看!2018年最优秀的9个Android Material Design Apps!

    今年4月,谷歌Gmail推出了全新的设计外观,全新的配色方案,更多的空白区域和精致的图标.也带来了Material Design 的一些改变 – Material Theming (材料主题),旨在自 ...

  6. Android Material Design :LinearLayoutCompat添加分割线divider

     Android Material Design :LinearLayoutCompat添加分割线divider Android Material Design 扩展支持包中的LinearLayo ...

  7. Android Material Design TabLayout属性app:tabMode和app: tabGravity

    Android Material Design TabLayout属性app:tabMode和app: tabGravity Android Material Design 中的TabLayout有两 ...

  8. 视频教程-Android Material Design 新控件-Android

    Android Material Design 新控件 刘志远,北京邮电大学硕士研究生, 北京育华志远科技有限公司创始人, 育华志远教育品牌负责人,育华志远课程体系打造者. 率领团队为互联网行业培训千 ...

  9. Android Material Design Icon Genenerator 插件为个人开发者提供 Icon 图标大全

    前言 如果你作为个人开发者,没有美工小姐姐的情况下,项目中的图标 icon 很是苦恼.之前用过阿里巴巴图标库 Iconfont,后来发现 Android studio 中有一个很牛逼的 icon 插件 ...

最新文章

  1. Redis实战之限制操作频率
  2. 【Android应用开发】分享一个录制 Android 屏幕 gif 格式的小技巧
  3. linux ssh命令 带密码,[命令] Linux 命令 sshpass(密码非交互式 ssh)(转载)
  4. java怎么来用urlrewrite伪静态化和urlrewrite的配置
  5. Java 并发编程-不懂原理多吃亏(送书福利)
  6. 关于华为P40登录谷歌闪退的问题
  7. Job 存储和持久化 (第五部分)
  8. 游戏match(【CCF】NOI Online能力测试2 提高组第三题 )
  9. 拓端tecdat|Python银行机器学习:回归、随机森林、KNN近邻、决策树、高斯朴素贝叶斯、支持向量机svm分析营销活动数据
  10. 压缩解压缩工具之WinRAR
  11. 数学建模之方差分析基础--单因素,双因素方差分析与matlab实现
  12. Ubuntu16.04安装Nvidia显卡驱动与cuda和Cudnn
  13. 小程序 banner 的使用
  14. 内存申请 GFP_KERNEL GFP_ATOMIC
  15. 文字校验的工具类--中文,电话号码,邮箱,身份证等信息的校验
  16. 【c++】判断一个点是否在三角形内部
  17. Foxmail 7.0中导入地址簿
  18. 信号的反射(振铃、台阶、回勾、尖峰毛刺)
  19. 苹果CMS完全开发文档 - 苹果CMS手册 - 苹果CMS教程 - 苹果CMS帮助 - 苹果cmsV10
  20. 音乐相册android studio,音乐相册

热门文章

  1. SuperCMS 上传漏洞!
  2. 自动化Build的方法如下所示
  3. 算法---------二叉树的后序遍历
  4. Android 有些机型hint不显示
  5. bootstrap bssuggest
  6. android屏幕关闭屏幕,如何在设备进入睡眠模式(屏幕关闭)时显示屏幕android?...
  7. python主要学哪些课程_Python学习课程大纲自学Python参考
  8. Android性能优化典范第二季
  9. 二维数组存放多个字符串_二维数组中输出多个最值及其下标。(仅供参考)
  10. 补充前几天测试用到的Linux命令