First
Specifically, you must first download the actionbarsherlock-master.zip and slidingmenu-master.zip open source files on github. then extract the two packages and import the library files in slidingmenu to an Eclipse project (here we do not emphasize the import of an android project ), the actionbarsherlock file in actionbarsherlock is imported to eclipse.
After the import, you need to set the library as a library to facilitate future calls in other projects. The specific operations are as follows:
1. Select the imported Library Project, ALT + enter
Click "android" and add the actionbarsherlock file (remember that the path of the actionbarsherlock file should not be a Chinese name, And the URL of the newly created project must be in the same workspace-workspace in the library ), check the islibrary above. The purpose of this step is to associate our library (the project just imported by slidingmenu) with the actionbarsherlock project because it uses some items in actionbarsherlock.
2. if the first step after some students found may report errors, this is because the library in the libs file package android-support-v4.jar and actionbarsherlock there is a difference, of course, because the Library Reference actionbarsherlock content, so we can delete the android-support-v4.jar in libs under the library, you can
3. Modify the slidingfragmentactivity. Java in the library to inherit the sherlockfragmentactivity.
4. After completing the above steps, we will create a new project to prove it. I first used the example import in slidingmenu to run perfectly without any flaws. Then I wanted to create a new one myself and I encountered a lot of trouble.
First, you need to delete the jar package under libs in your new project. Some of them are good, but I am not lucky. the Java file cannot be found. The following error message is displayed. Some information is displayed by default in actionbarsherlock,
Later, I found that I needed to modify the androidmainfest in the new project. change theme in the XML file to Android: theme = "@ style/theme. sherlock "> now, I want to thank the" Xin Chen "who helped me.
However, there is still a problem, and the r file still cannot be found. This is because the amount of eclipse version I use may be too high and it will depend on another package when creating a new project, this is the reason why a package is automatically exceeded every time I create a new project. Then, many items in the lock dependency package conflict with the library, and some of them have already been defined, so I decided to delete this package, continue to see where the error was reported, find the place where the error was reported, continue to delete it, and then change the class inherited by mainactivity to the original activity, if you find any menu-related items, continue to delete them.
Next, we will summarize some attributes of slidingmenu.
Common slidingmenu attributes:
Menu. setmode (slidingmenu. Left); // you can specify the left sliding menu.
Menu. settouchmodeabove (slidingmenu. touchmode_fullscreen); // you can set the sliding screen range, which can be swiped in full screen mode.
Menu. setshadowdrawable (R. drawable. Shadow); // sets the shadow image.
Menu. setshadowwidthres (R. dimen. shadow_width); // you can specify the width of the Shadow image.
Menu. setbehindoffsetres (R. dimen. slidingmenu_offset); // remaining width displayed on the home page when slidingmenu is selected
Menu. setbehindwidth (400); // you can specify the slidingmenu width.
Menu. setfadedegree (0.35f); // gradient degree of slidingmenu sliding
Menu. attachtoactivity (this, slidingmenu. sliding_content); // append slidingmenu to activity
Menu. setmenu (R. layout. menu_layout); // sets the layout file of the menu.
Menu. Toggle (); // dynamically determines whether slidingmenu is automatically disabled or Enabled
Menu. showmenu (); // display slidingmenu
Menu. showcontent (); // display content
Menu. setonopenlistener (onopenlistener); // listen to slidingmenu to open
There are two listeners for disabling the menu. In simple terms, for the menu Close event, one is when and the other is after
Menu. onclosedlistener (onclosedlistener); // listen to slidingmenu to close the current event
Menu. onclosedlistener (onclosedlistener); // listen to the event after slidingmenu is disabled
You can specify the slidingmenu on both the left and right.
Menu. setmode (slidingmenu. left_right); properties, and then set the layout file of the right menu
Menu. setsecondaryshadowdrawable (R. drawable. shadowright); // shadow image on the right menu
Set slidingmenu Properties
Sm = getslidingmenu ();
// If only the left menu is displayed, left is used, right is on the right, and left and right are supported.
SM. setmode (slidingmenu. left_right); // you can specify whether the menu appears on the left or right or both sides of the menu.
SM. setshadowdrawable (R. drawable. Shadow); // sets the shadow image resource.
SM. setshadowwidthres (R. dimen. shadow_width); // you can specify the width of the Shadow image.
// SM. setbehindwidth (200); // set the menu width
SM. setbehindoffsetres (R. dimen. slidingmenu_offset); // The remaining width displayed on the home page when slidingmenu is selected
SM. settouchmodeabove (slidingmenu. touchmode_fullscreen); // you can specify the sliding area.
Menu can be selected on the right:
// Slidingmenu supports both sides of the left and right menus, which do not conflict with each other and have beautiful animations and a good experience.
SM. setsecondarymenu (R. layout. menu_frame2); // you can specify the right menu.
SM. setsecondaryshadowdrawable (R. drawable. shadowright); // sets the image resource of the right-side menu shadow.
// Fragment of slidingmenu on the right
Getsuppfrfragmentmanager (). begintransaction (). Replace (R. Id. menu_frame2, new samplelistfragment (). Commit ();
Slidingmenu = getslidingmenu ();
// Set whether to slide left or right or left.
Slidingmenu. setmode (slidingmenu. left_right );
// Set the shadow width
Slidingmenu. setshadowwidth (getwindowmanager (). getdefadisplay display (). getwidth ()/40 );
// Set the left menu shadow Image
Slidingmenu. setshadowdrawable (R. drawable. Shadow );
// Set the right menu shadow Image
Slidingmenu. setsecondaryshadowdrawable (R. drawable. right_shadow );
// Set the ratio of menus to screens
Slidingmenu. setbehindoffset (getwindowmanager (). getdefadisplay display (). getwidth ()/5 );
// Set whether the menu fades in or out when sliding
Slidingmenu. setfadeenabled (true );
// Set the fade-in/fade-out ratio
Slidingmenu. setfadedegree (0.4f );
// Set the drag effect when sliding
Slidingmenu. setbehindscrollscale (0 );
// Set the range for sliding the menu and touching the screen
Slidingmenu. settouchmodeabove (slidingmenu. touchmode_fullscreen );
Attach a simple section written by yourself
SlidingMenu menu = new SlidingMenu(this);menu.setMode(SlidingMenu.LEFT);menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);menu.setShadowWidthRes(R.dimen.shadow_width);menu.setShadowDrawable(R.drawable.shadow);menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);menu.setFadeDegree(0.35f);menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);menu.setMenu(R.layout.left_drawer_fragment);menu.setOnOpenedListener(new SlidingMenu.OnOpenedListener() {@Overridepublic void onOpened() {// TODO Auto-generated method stub}}); init();}
public void init() {//LayoutInflater inflater = LayoutInflater.from();//setVisible(R.layout.left_drawer_fragment);mLinearLayout = (LinearLayout)findViewById(R.id.textLayout);mTextView1 = (TextView) findViewById(R.id.textview1);mTextView2 = (TextView) findViewById(R.id.textview2);mTextView3 = (TextView) findViewById(R.id.textview3);mTextView4 = (TextView) findViewById(R.id.textview4);mTextView5 = (TextView) findViewById(R.id.textview5);mTextView6 = (TextView) findViewById(R.id.textview6);mTextView1.setOnClickListener(this);mTextView2.setOnClickListener(this);mTextView3.setOnClickListener(this);mTextView4.setOnClickListener(this);mTextView5.setOnClickListener(this);mTextView6.setOnClickListener(this);}@Overridepublic void onClick(View view) {// TODO Auto-generated method stubswitch (view.getId()) {case R.id.textview1:mLayout.setBackgroundColor(Color.BLUE);break;case R.id.textview2:mLayout.setBackgroundColor(Color.GREEN);break;case R.id.textview3:case R.id.textview4:case R.id.textview5:case R.id.textview6:mLayout.setBackgroundColor(Color.WHITE);break;}}
Find a replacement for the only image used.