Floatingactionbutton
Hover button: Floatingactionbutton is rewrite ImageView, all Floatingactionbutton have ImageView all attributes.
- App:backgroundtint-Sets the background color of the fab.
- App:ripplecolor-Sets the background color when the fab is clicked.
- App:borderwidth- This property is particularly important if you do not set 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".
- App:elevation-The shadow size of the FAB in the default state.
- App:pressedtranslationz-The shadow size of the fab when clicked.
- App:fabsize-Sets the size of the FAB, which has two values, normal and Mini, and the corresponding fab sizes are 56DP and 40DP, respectively.
- SRC-Set the Fab's icon, Google recommends that the icon size is 24DP to match the design.
- App:layout_anchor-Sets the anchor point of the Fab, that is, which control sets the position for the reference point.
- App:layout_anchorgravity-Sets the location of the Fab relative anchor point, with values Bottom, center, right, left, top, and so on.
< Android.support.design.widget.FloatingActionButton Android:layout_width = "Wrap_content" android:layout_height= "Wrap_content" = "true" = "true" android:layout_margin= "20DP" android:src= "@mipmap/ic_launcher "/>
Effect:
:
Navigationview
It is easier to implement by providing the framework required for drawer navigation, and it is also able to directly generate navigational elements directly from menu resource files. Use Navigationview as a content view for drawerlayout. Navigationview handles the relationship with the status bar and ensures that the navigationview is properly interacting with the status bar on the api21+ device.
XML file:
Using Drawerlayout as the parent layout, you can realize the function of skidding
<?XML version= "1.0" encoding= "Utf-8"?><Android.support.v4.widget.DrawerLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Xmlns:app= "Http://schemas.android.com/apk/res-auto"Android:id= "@+id/drawer_layout"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:paddingbottom= "@dimen/activity_vertical_margin"Tools:context= "Fanggao.qf.toolbar_drawerlayout_navigationview_floactionbar_snackbar." Mainactivity "><!--Main interface - <RelativelayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <Android.support.v7.widget.ToolbarAndroid:id= "@+id/toolbar"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"> <!--Custom Layouts - </Android.support.v7.widget.Toolbar> <!--Suspended Circle - <Android.support.design.widget.FloatingActionButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true"Android:layout_alignparentright= "true"Android:layout_margin= "20DP"android:src= "@mipmap/ic_launcher"/> </Relativelayout><!--left Menu android:layout_gravity = "Start" On the left side of the layout -<Android.support.design.widget.NavigationViewAndroid:layout_width= "250DP"Android:layout_height= "Match_parent"android:layout_gravity= "Start"App:headerlayout= "@layout/layout_header"App:menu= "@menu/menu"/></Android.support.v4.widget.DrawerLayout>
View Code
Layout_header.xml
Header header in the side-slip menu:
<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:background= "#aaaaaa"> <ImageViewAndroid:id= "@+id/img_icon"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centerinparent= "true"android:src= "@mipmap/ic_launcher"/> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "HELLO"Android:layout_below= "@id/img_icon"android:textsize= "30SP"Android:layout_margin= "20DP"Android:layout_centerhorizontal= "true"/></Relativelayout>
View Code
Menu.xml Menu Layout
<?XML version= "1.0" encoding= "Utf-8"?><Menuxmlns:android= "Http://schemas.android.com/apk/res/android"> <!--menu supports grouping and sub-headings, but sub-headings do not support icon - <!--Radio - <Group> <ItemAndroid:title= "Active"Android:icon= "@mipmap/ic_launcher"> </Item> <ItemAndroid:title= "Member"Android:icon= "@mipmap/ic_launcher"> </Item> <ItemAndroid:title= "purse"Android:icon= "@mipmap/ic_launcher"> </Item> </Group> <!--Menu - <ItemAndroid:title= "Options"Android:icon= "@mipmap/ic_launcher"> <Menu> <ItemAndroid:title= "Favorites"></Item> <ItemAndroid:title= "positive"></Item> </Menu> </Item></Menu>
Main
Public classMainactivityextendsappcompatactivity {PrivateToolbar Toolbar; PrivateDrawerlayout drawerlayout; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity1_main); Toolbar=(Toolbar) Findviewbyid (R.id.toolbar); Drawerlayout=(drawerlayout) Findviewbyid (r.id.drawer_layout); //set the main titleToolbar.settitle ("title"); //Set subtitleToolbar.setsubtitle ("Subclass of title"); //Set iconToolbar.setlogo (R.mipmap.ic_launcher); //set toolbar and drawerlayout for animation and linkage This. Setsupportactionbar (toolbar); //left menu and toolbar linkage//Add a return icon to the left of the upper left iconGetsupportactionbar (). setdisplayhomeasupenabled (true); Getsupportactionbar (). sethomebuttonenabled (true);//set the return key to be available//Actionbardrawertoggle can monitor the drawer opening and closing events, can be considered as Drawerlistener sub-class//declares the Mdrawertoggle object, where R.string.open and r.string.close can be simply replaced with "open" and "close"Actionbardrawertoggle Actionbardrawertoggle =NewActionbardrawertoggle (mainactivity. This, Drawerlayout, R.string.open, R.string.close) {@Override Public voidondraweropened (View drawerview) {Super. ondraweropened (Drawerview); LOG.I ("Tag", "Ondraweropened:"); } @Override Public voidondrawerclosed (View drawerview) {Super. ondrawerclosed (Drawerview); LOG.I ("Tag", "Ondrawerclosed:"); } }; //keeps the icon and drawer in syncactionbardrawertoggle.syncstate (); //The monitoring realizes the opening and closing of the side bar, i.e. the closing and open of the drawer drawer.Drawerlayout.adddrawerlistener (Actionbardrawertoggle); }}
Effect:
The Navigationview of the Android design package combines the use of Drawerlayout,toolbar, Floatingactionbutton