Integrated Android Slidingmenu (Slidemenu)

Source: Internet
Author: User



Around the following:

Left


Right


Android Slidingmenu (slidemenu) is an open source project framework. On git:https://github.com/jfeinstein10/SlidingMenu

Now based on fragment gives a simple left + right slidingmenu (slidemenu). The first is to introduce a third-party library, which is no more than say, now to git to download the latest project code to local and then import into the project, the next step is to import and write their own code.

Main activity:

<span style= "FONT-SIZE:14PX;" >package Zhangphil.slidingmenu;import Com.jeremyfeinstein.slidingmenu.lib.slidingmenu;import Android.graphics.color;import Android.os.bundle;import Android.support.v4.app.fragment;import Android.support.v4.app.fragmentactivity;import Android.support.v4.app.fragmentmanager;import Android.support.v4.app.fragmenttransaction;import Android.view.gravity;import Android.view.KeyEvent;import Android.view.layoutinflater;import Android.view.view;import Android.view.viewgroup;import Android.widget.TextView ;p ublic class Mainactivity extends Fragmentactivity {private slidingmenu menu;//ID used to differentiate left or right side slip menuprivate final static String id = "id"; @Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); menu = new Slidingmenu (this);//Menu.setmode (Slidingmenu.left_right) left and right ; Menu.attachtoactivity (this, slidingmenu.sliding_content);//Left Menu.setmenu (r.layout.left_menu);// Right Menu.setsecondarymENU (r.layout.right_menu); Fragment leftfragment = Testfragment.newinstance ("left"); Fragment rightfragment = testfragment.newinstance ("right"); Fragmentmanager fm = Getsupportfragmentmanager (); Fragmenttransaction ft = fm.begintransaction (); Ft.replace (R.id.left, leftfragment); Ft.commit ();// Must regain a fragmenttransaction again. Otherwise the error. FT = Fm.begintransaction (); Ft.replace (R.id.right, rightfragment); Ft.commit ();} @Overridepublic boolean onKeyDown (int keycode, keyevent event) {//press back + no repeat if (keycode = = Keyevent.keycode_back & & Event.getrepeatcount () = = 0) {//The user presses the back key and switches Slidemenu <--> main interface. Menu.toggle (True); return true;} Return Super.onkeydown (KeyCode, event);} Only the fragment used to generate the test. public static class Testfragment extends Fragment {public static Fragment newinstance (String id) {Fragment Fragment = NE W testfragment (); Bundle bundle = new bundle (); bundle.putstring (ID, id); fragment.setarguments (bundle); return fragment;} @Overridepublic View Oncreateview (layoutinflater inflater, ViewGroup ContaiNer,bundle savedinstancestate) {//display only one textview. TextView TV = new TextView (getactivity ()); Tv.settextcolor (Color.Black); Tv.settext (This.getarguments (). getString (ID ) + ""); Tv.settextsize (60.0f); tv.setgravity (Gravity.center); return TV;}} </span>


Rewritten the onkeydown, in order to catch the event that the user presses the return key, in order to toggle.


Activity_main.xml:

<span style= "FONT-SIZE:14PX;" ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:layout_width= " Match_parent "    android:layout_height=" match_parent ">        <textview        android:id=" @+id/textview "        android:layout_width= "wrap_content"        android:layout_height= "wrap_content"        android:layout_ Centerinparent= "true"        android:text= "Slidemenu small demo"/>    </RelativeLayout></span>

Left_menu.xml

<span style= "FONT-SIZE:14PX;" ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:orientation= " Vertical "     android:layout_width=" match_parent "     android:layout_height=" match_parent ">    < Framelayout            android:id= "@+id/left"            android:layout_width= "match_parent"          android:layout_height= "0px"            android:layout_weight= "1" >    </FrameLayout></LinearLayout></span>

Right_menu.xml

<span style= "FONT-SIZE:14PX;" ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:orientation= " Vertical "     android:layout_width=" match_parent "     android:layout_height=" match_parent ">    < Framelayout            android:id= "@+id/right"            android:layout_width= "match_parent"          android:layout_height= "0px "            android:layout_weight=" 1 ">    </FrameLayout></LinearLayout></span>


Integrated Android Slidingmenu (Slidemenu)

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.