The implementation method of floating Actionbutton for Android development suspension button _android

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.