<linearlayout android:id= "@+id/pop_layout" android:layout_width= "fill_parent" android:layout_height= "WR Ap_content "android:gravity=" center_horizontal "android:orientation=" vertical "Android:layout_alignparentbo Ttom= "true" android:background= "@drawable/btn_style_alert_dialog_background" > <button Android:id= "@+id/btn_take_photo" android:layout_marginleft= "20dip" android:layout_marginright= "20di P "android:layout_margintop=" 20dip "android:layout_width=" Fill_parent "android:layout_height=" W Rap_content "android:text=" photo "android:background=" @drawable/btn_style_alert_dialog_button "and roid:textstyle= "Bold"/> <button android:id= "@+id/btn_pick_photo" Android:layout_ marginleft= "20dip" android:layout_marginright= "20dip" android:layout_margintop= "5dip" Android : Layout_width= "Fill_pareNT "android:layout_height=" wrap_content "android:text=" select "Android:background=" from the album @drawable/BT N_style_alert_dialog_button "android:textstyle=" bold "/> <button android:id=" @+i D/btn_cancel "android:layout_marginleft=" 20dip "android:layout_marginright=" 20dip "Android:layout_ margintop= "15dip" android:layout_marginbottom= "15dip" android:layout_width= "Fill_parent" Android: layout_height= "Wrap_content" android:text= "Cancel" android:background= "@drawable/btn_style_alert_dialog_cancel "Android:textcolor=" #ffffff "android:textstyle=" bold "/> </LinearLayout>
import android.app.Activity; Import Android.content.Context; Import android.graphics.drawable.ColorDrawable; Import Android.view.LayoutInflater; Import android.view.MotionEvent; Import Android.view.View; Import Android.view.View.OnClickListener; Import Android.view.View.OnTouchListener; Import Android.view.ViewGroup.LayoutParams; Import Android.widget.Button; Import Android.widget.PopupWindow; Public classSelectpicpopupwindow extends Popupwindow {PrivateButton Btn_take_photo, Btn_pick_photo, Btn_cancel; PrivateView Mmenuview; PublicSelectpicpopupwindow (Activity context,onclicklistener Itemsonclick) {super (context); Layoutinflater Inflater=(layoutinflater) context. Getsystemservice (Context.layout_inflater_service); Mmenuview= Inflater.inflate (R.layout.alert_dialog,NULL); Btn_take_photo=(Button) Mmenuview.findviewbyid (R.id.btn_take_photo); Btn_pick_photo=(Button) Mmenuview.findviewbyid (R.id.btn_pick_photo); Btn_cancel=(Button) Mmenuview.findviewbyid (r.id.btn_cancel); //Cancel ButtonBtn_cancel.setonclicklistener (NewOnclicklistener () { Public voidOnClick (View v) {//destroy pop-up boxesdismiss (); } }); //Set Button ListenerBtn_pick_photo.setonclicklistener (Itemsonclick); Btn_take_photo.setonclicklistener (Itemsonclick); //set the view of Selectpicpopupwindow This. Setcontentview (Mmenuview); //sets the width of the Selectpicpopupwindow pop-up form This. SetWidth (layoutparams.fill_parent); //sets the height of the Selectpicpopupwindow pop-up form This. SetHeight (layoutparams.wrap_content); //set the Selectpicpopupwindow pop-up form to click This. setfocusable (true); //set Selectpicpopupwindow pop-up form animation effect This. Setanimationstyle (R.style.animbottom); //instantiate a colordrawable color as translucentColordrawable DW =NewColordrawable (0xb0000000); //set the background of a Selectpicpopupwindow pop-up form This. setbackgrounddrawable (DW); //Mmenuview Add Ontouchlistener Monitor to get the touch screen position if outside the selection box, destroy the popup boxMmenuview.setontouchlistener (NewOntouchlistener () { PublicBoolean OnTouch (View V, motioneventEvent) { intHeight =Mmenuview.findviewbyid (r.id.pop_layout). GetTop (); intY= (int)Event. GetY (); if(Event. getaction () = =motionevent.action_up) { if(y<height) {Dismiss (); } } return true; } }); } }
//add a listener to the text control and click the Play Definition windowTv.setonclicklistener (NewOnclicklistener () { Public voidOnClick (View v) {//Instantiate SelectpicpopupwindowMenuwindow =NewSelectpicpopupwindow (mainactivity. This, Itemsonclick); //Display windowMenuwindow.showatlocation (mainactivity. This. Findviewbyid (R.id.main), gravity.bottom| Gravity.center_horizontal,0,0);//To set the location that layout displays in Popupwindow } }); } //implementing a listener class for a pop-up window PrivateOnclicklistener Itemsonclick =NewOnclicklistener () { Public voidOnClick (View v) {Menuwindow.dismiss (); Switch(V.getid ()) { CaseR.id.btn_take_photo: Break; CaseR.id.btn_pick_photo: Break; default: Break; }
Android Popupwindow implementation to pop up from the bottom or slide out of the Select menu or window