[Android] news client introduces slidingmenu
Download slidingmenu, https://github.com/jfeinstein10/SlidingMenu
Import library
Right click our project = = > properties = = > Android = = > Library add to add a third-party project as a dependency
This error occurs: found 2 versions of android-support-v4.jar in the dependency list
Because the android-support-v4.jar package in the third-party project conflicts with that in our project, it is OK to use our jar package to overwrite the of the third-party project
The current activity inherits the slidingfragmentactivity and overrides the oncreate() method,
Call setbehidcontentview() to set the layout file of the sliding menu. Parameter: resource ID
Get the slidingmenu object through the getslidingmenu() method
Call the setmode() method of the slidingmenu object to set the left row. Parameter: slidingmenu.left
Call setbehindwidthres() of the slidingmenu object to set the width of the menu. Parameter: width dimension resource
Call the setshadowdrawable() method of the slidingmenu object to set the menu shadow. Parameter: shape resource file
Shape resource file, add root node < Shape >
Add a gradient node, < gradient >, and set the start color Android: startcolor = "#000000"
Set the middle color, Android: centercolor = "2d000000"
Set end color, Android: endcolor = "5a000000"
Call setshadowwidth() of the slidingmenu object to set the width of the shadow. Parameter: width
Call the settouchmodeabove() method of the slidingmenu object to set the sliding range,
Parameter: slidingmenu.touchmode_ Fullscreen full screen
SlidingMenu.TOUCHMODE_ None sliding is not allowed
Call requestwindowfeature(), parameter: window.feature_ NO_ Title, remove the title
Create fragment
Create a new package xxx.fragment, a new menufragment, and inherit the fragment in the V4 package
Override oncreate()
Override oncreateview() and pass in the layoutinflator object
Create a new layout file, list_ View.xml, which contains a listview control, and calls the layoutinflator object inflate() method to convert it into a view object
Override onactivitycreated() when the activity is created
Call findviewbyid() of the view object to get the listview object
Call setadapter() method of listview object to set adapter. Parameters: adapter object
Get arrayadapter object, construction method, parameters: context, layout resource, text control ID, data list
Context (getactivity ()), the layout resource uses android.r.layout.simple of the system_ list_ item1
Text ID android.r.id.text1, data
Replace layout
In the activity, get the fragment object and replace the menu layout with this fragment
Get the fragment object, new menufragment()
Call getsuportfragment(). Begintransaction(). Replace(). Commit() to replace
Replace() method, parameters: layout ID, fragment object
MainActivity.java
MenuFragment.java