Step One:
In Build.gradle, add the following code to import the package
{ compile ‘com.android.support:design:22.2.0‘}
Step Two:
Add the following code to the XML file
<android.support.design.widget.FloatingActionButton android:id="@+id/bt_auction" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:src="@drawable/headerarrow" app:fabSize="normal" />
Step Three:
Adding Listener Events
FloatingActionButton actionButton = (FloatingActionButton) findViewById(R.id.bt_auction);actionButton.setOnClickListener(new View.OnClickListener() { @Override publicvoidonClick(View v) { //监听事件 }});
Note the point:
One: How to change the floating button color
According to the official document interpretation, there is no property can change the button color, the color of this button is taken from the item's theme color, so you can change the theme style "Coloraccent" Value change button color
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="colorAccent">#FF4081</item> </style>
Second: How to change the color when the button is pressed
Add the following attribute to the XML file
app:rippleColor="#ff0000"
Three: How to change the button size
The default is 2 sizes to select "Normal" and "mini"
app:fabSize="normal"
Excerpt from Android Developer blog
Floating Action button (floating button)--Google's new design package