Third-party library SlidingMenu, third-party library slidingmenu

Source: Internet
Author: User

Third-party library SlidingMenu, third-party library slidingmenu

Use development tools: IntelliJ community Edition

SlidingMenu download: https://github.com/jfeinstein10/SlidingMenu

The overall process is as follows:

File-> Import Module Import three projects

The example project of SlidingMenu references Theme and style in ActionBarSherlock, so you need to import the ActionBarSherlock project. ActionBarSherlock download: https://github.com/JakeWharton/ActionBarSherlock

 

Add reference: the example project uses two other libraries and adds reference in settings (right-click open module settings.

 

 

 

Add v4 package reference to the example project. Note that the support package used by the example project, library, and ActionBarSherlock library must be the same, you need to use the v4 package in the same position when adding and referencing v4.

 

 

The other two projects also need to add v4 packages, the same operation.

Delete the v4 package in the libs directory of the library based on the preceding reasons.

 

 

 

Test is added to the ActionBarSherlock library, so you can delete the test directory if you do not need it.

Last step:

In the com. jeremyfeinstein. slidingmenu. exampleBaseActivity class, 53 rows (different versions may be different:

Getsuppactionactionbar (). setDisplayHomeAsUpEnabled (true );

An error is reported, so you need to modify

The SlidingFragmentActivity in the com. jeremyfeinstein. slidingmenu. lib. app package (the shortcut key is to press shift twice to search for it), so that it inherits from the SherlockFragmentActivity.

 

In addition, I was not familiar with using third-party libraries at the beginning, so I tried a stupid method and it was available after testing. Copy the resource files under the res directory and class files under src used in the library and ActionBarSherlock libraries to example, however, because the resource file directories used in different library classes (that is, the Directory of the R file) are different, there are many manual changes ...... bytes

Appendix: the directories after two third-party libraries are downloaded and decompressed are as follows:

Directory in the SlidingMenu-master Folder:

 

Directory in the ActionBarSherlock-master Folder:

 

 

 

Simple use in your project:

Add member variables

Private Fragment mContent;

In the onCreate () method, add

If (savedInstanceState! = Null)
MContent = getsuppfrfragmentmanager (). getFragment (savedInstanceState, "mContent ");
If (mContent = null)
MContent = new ColorFragment (R. color. red );

And the following code

SetBehindContentView (R. layout. menu_frame );
Getsuppfrfragmentmanager ()
. BeginTransaction ()
. Replace (R. id. menu_frame, new ColorMenuFragment ())
. Commit ();
GetSlidingMenu (). setTouchModeAbove (SlidingMenu. TOUCHMODE_FULLSCREEN );
GetSlidingMenu (). setBehindOffsetRes (R. dimen. slidingmenu_offset );

Rewrite Method

@ Override
Public void onSaveInstanceState (Bundle outState ){
Super. onSaveInstanceState (outState );
Getsuppfrfragmentmanager (). putFragment (outState, "mContent", mContent );
}

Define the following method

Public void switchContent (Fragment fragment ){
MContent = fragment;
Getsuppfrfragmentmanager ()
. BeginTransaction ()
. Replace (R. id. main, fragment)
. Commit ();
GetSlidingMenu (). showContent ();
}

Copy the resource files under the drawable and values directories to the corresponding directory of your project.

Copy the desired fragment class file and the corresponding layout file to your project.

 

Set whether the actionbar is also moved

SetSlidingActionBarEnabled (false );

 

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 );

 

Some methods in SlidingFragmentActivity are rewritten to final. Therefore, when you re-write the Activity method in Actvitiy created by yourself, the method in SlidingFragmentActivity is overwritten.

For example

@ Override
Public boolean onCreateOptionsMenu (com. actionbarsherlock. view. Menu menu ){
Com. actionbarsherlock. view. MenuInflater menuInflater = getSupportMenuInflater ();
MenuInflater. inflate (R. menu. menu_main, menu );
Return true;
}

 

 

Related Article

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.