Floating Action button (floating button)--Google's new design package

Source: Internet
Author: User

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

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.