FloatingActionButton的使用

参考:http://blog.csdn.net/lmj623565791/article/details/46678867android

 

添加依赖: compile 'com.android.support:design:22.2.0' app

布局:布局

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right|bottom"
    android:src="@drawable/ic_discuss"
    />

 

  • 填充色以及按下的颜色如何自定义呢?

按下的颜色是 rippleColor ,默认取的是主题中的 colorControlHighlight 测试

填充色是 backgroundTint ,默认取的是主题中的 colorAccent (这个属性好像要API21才能用)spa

注:colorAccent 对应EditText编辑时、RadioButton选中、CheckBox等选中时的颜色。.net

 

也能够直接用属性定义这两个的颜色:code

app:backgroundTint="#ff87ffeb"
app:rippleColor="#33728dff"

 

  • 立体感有没有什么属性能够动态指定?

和立体感相关有两个属性,elevation和pressedTranslationZ,前者用户设置正常显示的阴影大小;后者是点击时显示的阴影大小。xml

<android.support.design.widget.FloatingActionButton
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|bottom"
        android:src="@drawable/ic_discuss"
        app:backgroundTint="#ff87ffeb"
        app:rippleColor="#33728dff"
        app:elevation="6dp"
        app:pressedTranslationZ="12dp"
        />

 

5.x存在的一些问题

在5.x的设备上运行,你会发现一些问题(测试系统5.0):blog

  • 木有阴影

添加属性 app:borderWidth="0dp" ip

  • 对于5.x设置一个合理的margin,总体以下:
 <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        app:borderWidth="0dp"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_headset" />

values

<dimen name="fab_margin">0dp</dimen>

values-v21

 <dimen name="fab_margin">16dp</dimen>

 

2015-06-29

17:35:25

相关文章
相关标签/搜索