First step: Layout file
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "Horizontal" > <LinearLayoutAndroid:id= "@+id/menu_close"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:background= "@drawable/menu_bg"//Background Image 9android:gravity= "Center"android:orientation= "vertical" > <LinearLayoutAndroid:id= "@+id/menu_close_btn"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:background= "@drawable/menu_btn_bg"//selectorandroid:gravity= "Center"android:orientation= "vertical" > <ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:src= "@drawable/btn_close" />//closed icons <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Exit"Android:textcolor= "#eee" /> </LinearLayout> </LinearLayout></LinearLayout>
The second click event to invoke the Popupwindow method
if(!Menu_display) {//If not shown//Get Layoutinflater InstanceInflater = (layoutinflater) This. Getsystemservice (Layout_inflater_service); //here the main layout is added in the inflate, oh, used to be direct this.setcontentview () it? Hehe//The method returns a View object that is the root of the layoutLayout = Inflater.inflate (R.layout.main_menu,NULL);Menuwindow =NewPopupwindow (Layout, layoutparams.fill_parent, layoutparams.wrap_content);//Menuwindow.showasdropdown (layout);//set the pop-up effect//menuwindow.showasdropdown (null, 0, layout.getheight ());Menuwindow.showatlocation ( This. Findviewbyid (R.id.mainweixin),//below the entire layout gravity.bottom| Gravity.center_horizontal, 0, 0);//To set the location that layout displays in Popupwindow//How do I get the controls in our main? It's simple, too .Mclose =(LinearLayout) Layout.findviewbyid (r.id.menu_close); mclosebtn =(linearlayout) layout. Findviewbyid (R.ID.MENU_CLOSE_BTN); //Here's a click event registration for each layout ... //For example, when you click on a MenuItem, his background color changes .//get some background pictures or colors in advance. mclosebtn. Setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View arg0) {//Toast.maketext (Main.this, "Exit",//Toast.length_long). Show ();Intent Intent =NewIntent (); Intent.setclass (mainweixin. This, Exit.class); StartActivity (Intent); Menuwindow.dismiss (); //Close Menu After responding to a click event } }); Menu_display=true; } Else{//shows the//If it is currently displayed, it is hidden.Menuwindow.dismiss (); Menu_display=false; }
Popupwindow---pop-up bottom form