First, introduce
This class is inherited from ImageView, so for this control we can use all the properties of ImageView
Ii. use of preparation, written in the Build.grade file of AS
Third, the use of instructions
In the XML file, note the Blue font section
<android.support.design.widget.floatingactionbutton
android:id= "@+id/floatingactionbutton"
android: Layout_width= "Wrap_content"
android:layout_height= "Wrap_content" android:layout_centerinparent= "true"
android:src= "@mipmap/ok"
app:borderwidth= "0DP"
app:backgroundtint= "#FF4011"
app:ripplecolor= "# 33728DFF "
app:elevation=" 8DP "
app:pressedtranslationz=" 16DP "
/>
You can see that we use the app attribute, then we need to add this attribute in the root container.
Property Description:
1, app:borderwidth= ""------------------border width, usually set to 0, to solve the problem that the shadow on the Android 5.X device does not display properly
2, app:backgroundtint= ""---------------the background color of the button, do not set, the default use of theme Coloraccent color
3, app:ripplecolor= ""--------------------Click on the Edge shadow color
4, app:elevation= ""----------------------the width of the edge shadow
5, app:pressedtranslationz= "16DP"-----Click the button, the button edge shadow width, usually set than the elevation value of the larger
In addition we would like to click on a color button, the normal state of a color to improve the user experience, then is the Drawable folder to create the file Floatbutton.xml
<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android=
"http://schemas.android.com/apk/res/" Android >
<item android:drawable= "@color/colornormal" ></item>
<item Android:state_ Pressed= "true" android:drawable= "@color/colorpressed" ></item>
</selector>
Then we set Floatactionbutton backgroud for this drawable file, and app:backgroundtint= "" property can no longer set
<android.support.design.widget.floatingactionbutton
android:id= "@+id/floatingactionbutton"
android: Layout_width= "Wrap_content"
android:layout_height= "wrap_content"
android:layout_centerinparent= "true"
android:background= "@drawable/floatbutton"
android:src= "@mipmap/ok"
app:borderwidth= "0DP"
app:ripplecolor= "#33728dff"
app:elevation= "8DP"
app:pressedtranslationz= "16DP"
/>
Effect Chart: