Android Learning note--design Two controls under the pack

Source: Internet
Author: User
Tags set background

Today we learned the two controls under the design package and recorded that we needed to rely on the first

1     Compile ' com.android.support:design:25.0.0 '

It can then be used in the XML file.

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Xmlns:tools= "Http://schemas.android.com/tools"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent"6 Tools:context= "Com.wuxianedu.alianxi.MainActivity"7 Xmlns:app= "Http://schemas.android.com/apk/res-auto">8     9     <Android. Support.design.widget.FloatingActionButtonTen Android:id= "@+id/button"android:layout_centerinparent= "true" One Android:layout_width= "Wrap_content"App:ripplecolor= "#FF4F4F" A Android:layout_height= "Wrap_content"app:fabsize= "Mini" - app:elevation= "40DP"App:pressedtranslationz= "50DP" - android:src= "@mipmap/ic_launcher"/> the </Relativelayout>

Property Description

  1. App:backgroundtint-Sets the background color.
  2. App:ripplecolor-Sets the background color when clicked.
  3. <span style="color: #cc0000;" >app:borderwidth-If the property is not set to 0DP, the Fab will appear as a square on the 4.1 SDK, and the SDK after 5.0 does not have a shadow effect. So set to borderwidth="0DP". </span>
  4. App:elevation-The shadow size is in default state.
  5. App:pressedtranslationz-the shadow size when clicked.
  6. App:fabsize-Sets the size, which has two values, normal and Mini, corresponding to 56DP and 40DP respectively.
  7. SRC-set icon, Google recommends that the icon size is 24DP to match the design.
  8. App:layout_anchor-Sets the anchor point, that is, which control sets the position for the reference point.
  9. App:layout_anchorgravity-Sets the position of the relative anchor point, with values Bottom, center, right, left, top, and so on.

In the XML file, set the

Write another component in the Java file below

1  PackageCom.wuxianedu.alianxi;2 3 ImportAndroid.graphics.Color;4 ImportAndroid.support.design.widget.FloatingActionButton;5 ImportAndroid.support.design.widget.Snackbar;6 Importandroid.support.v7.app.AppCompatActivity;7 ImportAndroid.os.Bundle;8 ImportAndroid.view.View;9 ImportAndroid.widget.TextView;Ten ImportAndroid.widget.Toast; One  A  Public classMainactivityextendsappcompatactivity { -  - @Override the     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -         //set a Click event for a component written in XML +Findviewbyid (R.id.button). Setonclicklistener (NewView.onclicklistener () { - @Override +              Public voidOnClick (view view) { A                 //using Snackbar pop-up information, atSnackbar Snackbar = Snackbar.make (view, "I am the message", Snackbar.length_long); -                 //Set OK button -Snackbar.setaction ("OK",NewView.onclicklistener () { - @Override -                      Public voidOnClick (view view) { -Toast.maketext (mainactivity. This, "OK", Toast.length_short). Show (); in                     } -                 }); to                 //change the color of pop-up information + Snackbar.setactiontextcolor (color.green); -                 //get to pop-up View menu theView views =Snackbar.getview (); *                 //Set Background Yans $ Views.setbackgroundcolor (color.blue);Panax NotoginsengTextView TextView =(TextView) Views.findviewbyid (r.id.snackbar_text); - Textview.settextcolor (color.yellow); the snackbar.show (); +             } A         }); the     } +}

Android Learning note--design Two controls under the pack

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.