Material Designer的低版本兼容实现(八)—— Flat Button
2014-12-04 19:40
387 查看
除了中规中矩的矩形按钮外,5.0中将按钮扁平化,产生了一个扁平按钮——Flat Button。这个按钮降低了很多存在感,主要用于在对话框,提示栏中。让整个界面减少层级。今天说的就是它的用法。
这个按钮继承自矩形按钮,所以拥有很多矩形按钮的属性,关于矩形按钮请看上一篇文章。
首先还是添加lib的依赖。lib地址:https://github.com/shark0017/MaterialDesignLibrary
一、放入布局文件
自定义命名空间:xmlns:app="http://schemas.android.com/apk/res-auto"
<com.gc.materialdesign.views.ButtonFlat android:layout_width="wrap_content" android:layout_height="wrap_content" />
现在是默认的模式,没有做任何设置。默认的状况是完全透明的一个按钮
[b]二、在布局文件中设置各种属性[/b]
android:background="@color/orange" 设置背景色,默认是透明的
android:text="Flat Button" 设置文字,默认没有文字
android:textSize="20sp" 设置文字大小,默认14sp,文字是粗体。
android:textColor="#ffc641" 设置文字颜色,默认是蓝色
app:rippleColor="#ffc641" 设置涟漪的颜色,默认是灰色
app:rippleSpeed="2" 设置涟漪扩散速度,默认6f
app:clickAfterRipple="false" 设置触发click事件的时间,默认是涟漪扩散完了再出发点击事件
[b]三、通过代码设定各种属性[/b]
public class ButtonFlatTest extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.button_flat); btn01.setBackgroundColor(getResources().getColor(R.color.orange));// 设定按钮背景 btn02.setBackgroundColor(0xffff0000);// 设定按钮背景 btn03.setText("setText");// 设定按钮文字 btn04.setTextSize(30);// 设定文字大小 btn05.setTextColor(0xffffc641);// 设定文字颜色 btn06.setTextColor(getResources().getColor(R.color.red));// 通过资源设定文字颜色 btn07.setRippleColor(0xffffc641);// 直接设定颜色数值 btn08.setRippleColor(getResources().getColor(R.color.orange));// 设定涟漪的颜色 btn09.setRippleSpeed(2);// 设置涟漪扩散速度 btn10.setClickAfterRipple(false);// 设定点击后立刻产生click事件 buttonFlat.getTextView();// 得到这个按钮中的textView对象,可以进行各种设定 } }
相关文章推荐
- 兼容低版本 IE 的 JScript 5.5 实现
- Javascript实现仿WebQQ界面的“浮云”兼容 IE7以上版本及FF
- Material Designer的低版本兼容实现(二)—— Theme
- Material Designer的低版本兼容实现(六)—— Ripple Layout
- android圆角View实现及不同版本这间的兼容
- 兼容低版本IE的JScript5.5实现
- Material Designer的低版本兼容实现(十一)—— Switch
- 安卓小技巧专栏(一)@TargetAPI + 版本判断实现高低API版本兼容
- android圆角View实现及不同版本这间的兼容(android3.0过后的版本)
- Material Designer的低版本兼容实现(九)—— Float Button & Small Float Button
- Javascript实现仿WebQQ界面的“浮云”兼容 IE7以上版本及FF
- CSS控制页面最大最小宽度和高度可兼容IE6版本的实现方法
- android圆角View实现及不同版本这间的兼容
- Material Designer的低版本兼容实现(一)—— 简介 & 目录
- android圆角View实现及不同版本这间的兼容
- 实现HPG加密之星版本之间密钥兼容的问题有感
- CSS控制页面最大最小宽度和高度可兼容IE6版本的实现方法
- AndrowListView实现(自定义游戏列表)防止屏幕闪烁,设置分割线android中不推荐的方法,要考虑向下兼容,用了推荐的新方法,可能不兼容旧版本系统的手机
- Material Designer的低版本兼容实现(四)—— ToolBar
- Material Designer的低版本兼容实现(十)—— CheckBox & RadioButton