Take the Slidingmenu on GitHub for example. : Jfeinstein10/slidingmenu
I. Introduction of Eclipse
1.import->existing Android Code into Workspace, select the library in the Import folder. ( choose Copy Projects into workspacae when importing, because the project and library are required to be in the same directory in Windows, or not add successfully ) right click to select Properties, Under Android, select the IS Library.
2. Introduce the library in the Androi program that will reference the library. Right click to select Properties, click Add to select the library you just imported.
3. After two steps above, the import has been successful in eclipse and can be used in your own project with this open source library.
4. After the operation found that there is an error, see the next discovery is Android-support-v4.jar package caused by the project Libs the following package deleted, normal operation.
Two. Introducing in Android Studio
1.file->new->import Module, select Library.
2. Right-click the project, select Project Structure, select your project, dependencies Select +-Module dependency, select the library.
Gradle in 3.Android Studio I have been not very understanding, according to the value of their own project dependencies, some sdkversion changed a bit.
Buildscript {repositories {mavencentral ()} dependencies {Classpath' com.android.tools.build:gradle:1.5.0 ' }}applyplugin:' Android-library 'dependencies {Compile' com.android.support:support-v4:13.0.0 '}android {compilesdkversion + Buildtoolsversion"19.1.0" Defaultconfig {minsdkversion the Targetsdkversion + } sourcesets {main {Java.Srcdirs= [' src '] Resources.Srcdirs= [' src ']Aidl.Srcdirs= [' src ']Renderscript.Srcdirs= [' src ']Res.Srcdirs= [' Res ']Assets.Srcdirs= [' Assets '] Manifest.Srcfile' Androidmanifest.xml ' } }}
After 4.build Gradle, you can apply the contents of the open Source Library to your project.
PackageAndroid.com.myndk;ImportAndroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.widget.TextView;ImportCom.jeremyfeinstein.slidingmenu.lib.SlidingMenu;Public classMainactivityextendsActivity {Static{System.loadLibrary("Myjni"); }Public Static nativeStringHello(); @Override protected voidonCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (r.layout.Activity_main); TextView textview= (TextView) Findviewbyid (r.id.TextView); Textview.settext (Hello()); //Configure the Slidingmenu Slidingmenu menu =NewSlidingmenu ( This); Menu.setmode (Slidingmenu. Left); //Set the mode of touch screen Menu.settouchmodeabove (Slidingmenu.Touchmode_fullscreen); Menu.setshadowwidthres (r.dimen.Activity_horizontal_margin); Menu.setshadowdrawable (r.drawable.Shadow); //Set the width of the Slide menu view Menu.setbehindoffsetres (r.dimen.Activity_horizontal_margin); //Set the value of the fade-in fade-out effect Menu.setfadedegree (0.35f); /*** Sliding_window'll include the Title/actionbar in the content* section of the Slidingmenu, while Sliding_content does not. */ Menu.attachtoactivity (This ,Slidingmenu.sliding_content); //Set the layout for the slide menu Menu.setmenu (r.layout.Menu); }}
Some of the parameters in the Slidingmenu is not very well understood, the value of random, the final attached to the program used, does not guarantee aesthetics, but the operation is not a problem.
Shadow.xml (under the Drawable folder)
<?XML version="1.0"encoding="Utf-8"?><shapexmlns:Android="Http://schemas.android.com/apk/res/android"><gradient Android: centercolor="#11000000" Android: endcolor="#33000000" Android: startcolor="#00000000"/></shape>
Dimens.xml (under the Values folder)
<resources> <!--Default screen margins, per the Android Design guidelines. c4> name="Activity_horizontal_margin">16dp</dimen> Name= " activity_vertical_margin">16dp </dimen ></resources>
Introducing open Source libraries in Android (Eclipse and Android Studio)