简单button样式的设置(不是直接将背景设置为图片,而是设置背景的颜色)
2016-10-22 22:51
344 查看
在以前,我们直接就是在button的brackgroundd中编写drawable,button的点击图片,但是现在我们统一通过style来实现样式的设置,这样设置,更加规范化
步骤:
1.首先编写button的代码:
2.看上面只有 style="@style/bigRedButton" ,这个样式没有定义,所以我们需要定义这个样式
在stytle中新建bigredButton的样式
3.我们看到上面bg_btn_style_red没有,所以要定义:
4.再看上面corners android:radius="@dimen/buttonCornerSize" />没有定义,我们需要在values中新建dimens的文件,然后在里面定义样式
最后就是我们的效果图:
步骤:
1.首先编写button的代码:
<Button android:id="@+id/btn_login" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="登 录" android:layout_marginTop="30dp" android:layout_margin="20dp" style="@style/bigRedButton" />
2.看上面只有 style="@style/bigRedButton" ,这个样式没有定义,所以我们需要定义这个样式
在stytle中新建bigredButton的样式
<!--button的样式--> <style name="bigRedButton" > <item name="android:background">@drawable/bg_btn_style_red</item> </style>
3.我们看到上面bg_btn_style_red没有,所以要定义:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="false"> <shape android:shape="rectangle"> <corners android:radius="@dimen/buttonCornerSize" /> <solid android:color="@color/red_btn_color_disable" /> </shape> </item> <item android:state_pressed="true"> <shape android:shape="rectangle"> <corners android:radius="@dimen/buttonCornerSize" /> <solid android:color="@color/red_btn_color_pressed" /> </shape> </item> <item> <shape android:shape="rectangle"> <corners android:radius="@dimen/buttonCornerSize" /> <solid android:color="@color/red_btn_color_normal" /> </shape> </item> </selector>
4.再看上面corners android:radius="@dimen/buttonCornerSize" />没有定义,我们需要在values中新建dimens的文件,然后在里面定义样式
<resources> <!-- Default screen margins, per the Android Design guidelines. --> <dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen> <dimen name="buttonCornerSize">2.0dip</dimen> </resources>
最后就是我们的效果图:
相关文章推荐
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- navigationItem.rightBarButtonItem 设置背景图片,颜色更改解决办法
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- 设置button不同状态下的背景色,即把这个颜色变成图片设置成,背景图片
- Flex中如何通过backgroundImage, backgroundColor和backgroundAlpha样式,设置VBox的背景图片和背景颜色以及改变透明度
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- PHPExcel-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- 黄聪:phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- navigationItem.rightBarButtonItem 设置背景图片,颜色更改解决的方法
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- PHPExcel-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- Qt中设置widget背景颜色/图片的注意事项(使用样式表 setStyleSheet())
- Qt中设置widget背景颜色/图片的注意事项(使用样式表 setStyleSheet())
- MFC中设置对话框颜色、添加背景图片、添加音乐的方法
- 给button设置背景图片不显示解决了
- Qt中设置widget背景颜色/图片的注意事项(使用样式表 setStyleSheet())
- VC 对话框设置背景颜色和图片