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
- App:backgroundtint-Sets the background color.
- App:ripplecolor-Sets the background color when clicked.
- <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>
- App:elevation-The shadow size is in default state.
- App:pressedtranslationz-the shadow size when clicked.
- App:fabsize-Sets the size, which has two values, normal and Mini, corresponding to 56DP and 40DP respectively.
- SRC-set icon, Google recommends that the icon size is 24DP to match the design.
- App:layout_anchor-Sets the anchor point, that is, which control sets the position for the reference point.
- 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