Android FloatingActionButton 使用介绍

1.布局文件介绍

由于使用的RelativeLayout,因此布局时使用的是相对布局.

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:src="@mipmap/ic_launcher"
    app:elevation="1sp"
    app:backgroundTint="#ff87ffeb"
    app:backgroundTintMode="src_over"
    app:fabSize="mini"
    app:pressedTranslationZ="1dp"
    app:rippleColor="#33728dff"
    app:useCompatPadding="true" />

a.其中elevation (海拔)指FAB的悬空高度.

如图为elevation=”1sp” 和 elevation=”10sp”的差别,看出有明显的阴影差别.

blob.pngblob.png

b.backgroundTint 背景着色

blob.png

c.backgroudTintMode 背景着色方式

blob.pngsrc_over

blob.pngsrc_in

……………………………………………稍后看看backgroundTintMode

d.fabsize

分为mini和normal 两种大小方式

e.pressedTranslationZ    点击后在Z轴上的投影

f.rippleColor    投影颜色

useCompatPadding

 

 

2.引用Android 官方的XML 属性


android.support.design:elevation

Elevation value for the FAB

Must be a dimension value, which is a floating point number appended with a unit such as “14.5sp“. Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form “@[package:]type:name“) or theme attribute (in the form “?[package:][type:]name“) containing a value of this type.

This is a private symbol.

Related Methods

android.support.design:fabSize

Size for the FAB.

Must be one of the following constant values.

Constant Value Description
normal 0
mini 1

This is a private symbol.

Related Methods

android.support.design:rippleColor

Ripple color for the FAB.

Must be a color value, in the form of “#rgb“, “#argb“, “#rrggbb“, or “#aarrggbb“.

This may also be a reference to a resource (in the form “@[package:]type:name“) or theme attribute (in the form “?[package:][type:]name“) containing a value of this type.

This is a private symbol.

Related Methods

android.support.design:useCompatPadding

Enable compat padding.

Must be a boolean value, either “true” or “false“.

This may also be a reference to a resource (in the form “@[package:]type:name“) or theme attribute (in the form “?[package:][type:]name“) containing a value of this type.

This is a private symbol.

Related Methods