Popupwindow---pop-up bottom form

Source: Internet
Author: User

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

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.