Let's take a look at the effect chart:
Menupopwindow:
Package Com.cloudeye.android.cloudeye.view;
Import android.app.Activity;
Import Android.content.Context;
Import android.graphics.drawable.ColorDrawable;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.AdapterView;
Import Android.widget.BaseAdapter;
Import Android.widget.ImageView;
Import Android.widget.ListView;
Import Android.widget.PopupWindow;
Import Android.widget.TextView;
Import COM.CLOUDEYE.ANDROID.CLOUDEYE.R;
Import Com.cloudeye.android.cloudeye.base.MenuPopwindowBean;
Import java.util.List;
/** * Created by Mr. Yuan on 2016/10/26. * * public class Menupopwindow extends Popupwindow {private View Conentview, private ListView lvcontent; public Menupopwin Dow (activity context, list<menupopwindowbean> List) {layoutinflater inflater = (layoutinflater) context.
Getsystemservice (Context.layout_inflater_service);
Conentview = inflater.inflate (R.layout.menu_popup_window, NULL); Lvcontent = (ListView) conentview.findviewByid (R.id.lv_toptitle_menu);
Lvcontent.setadapter (New Myadapter (context, list));
int h = Context.getwindowmanager (). Getdefaultdisplay (). GetHeight ();
int w = Context.getwindowmanager (). Getdefaultdisplay (). GetWidth ();
Set Selectpicpopupwindow view This.setcontentview (Conentview);
Sets the width this.setwidth (w/3-30) of the Selectpicpopupwindow pop-up form;
Set the high This.setheight (ViewGroup.LayoutParams.WRAP_CONTENT) of the Selectpicpopupwindow pop-up form;
Set Selectpicpopupwindow pop-up form to click This.setfocusable (TRUE);
This.setoutsidetouchable (TRUE);
Refresh Status This.update ();
Instantiate a colordrawable color for semitransparent colordrawable DW = new colordrawable (0000000000);
Click the back key and other places to make it disappear, set this to trigger Ondismisslistener, set other control changes such as Operation This.setbackgrounddrawable (DW); Mpopupwindow.setanimationstyle (Android.
R.style.animation_dialog);
Set the Selectpicpopupwindow pop-up form animation effect This.setanimationstyle (R.style.animationpreview);
} public void Setonitemclick (Adapterview.onitemclicklistener myonitemclicklistener) {
Lvcontent.setonitemclicklistener (Myonitemclicklistener);Class Myadapter extends Baseadapter {private list<menupopwindowbean> List; private Layoutinflater inflater; publi C Myadapter (context context, list<menupopwindowbean> List) {inflater = Layoutinflater.from (context); this.list = L
Ist @Override public int GetCount () {return list = = null 0:list.size () @Override public Object getitem (int position) {return list.get (position);} @Override public long getitemid (int position) {return position;} @Override public View g Etview (int position, View Convertview, ViewGroup parent) {Holder Holder = null; if (Convertview = null) {Convertview =
Inflater.inflate (R.layout.menu_popup_window_item, NULL);
Holder = new Holder ();
Holder.ivitem = (ImageView) Convertview.findviewbyid (R.id.iv_menu_item);
Holder.tvitem = (TextView) Convertview.findviewbyid (R.id.tv_menu_item);
Convertview.settag (holder);
else {holder = (holder) Convertview.gettag ();} holder.ivItem.setImageResource (List.get (position). GetIcon ()); Holder.tvItem.setTexT (list.get (position). GetText ());
return convertview;
Class Holder {ImageView ivitem;
TextView Tvitem; }/** * Show Popupwindow * * @param parent/public void Showpopupwindow (View parent) {if (!this.isshowing ()) {//below pull mode display
Popupwindow This.showasdropdown (parent);
else {This.dismiss ();}} }
Menupopwindow layout:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
android:layout_width=" match_parent "
android:layout_height=" match_parent "
android:o" rientation= "vertical"
android:paddingright= "10DP" >
<listview
android:id= "@+id/lv_toptitle_" Menu "
android:layout_width=" match_parent "
android:layout_height=" wrap_content "
android:background = "@mipmap/back_toptitle_menu"/>
</LinearLayout>
Item layout file in adapter:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
android:layout_width=" match_parent "
android:layout_height=" Match_parent "
android: gravity= "center"
android:orientation= "horizontal"
android:paddingbottom= "10DP"
android:paddingtop= "10DP" >
<imageview
android:id= "@+id/iv_menu_item"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_gravity= "center_vertical"
android:layout_ marginright= "10DP"
android:src= "@mipmap/icon_menu_item_edit"/>
<textview android:id=
"@+id /tv_menu_item "
android:layout_width=" wrap_content "
android:layout_height=" Wrap_content "
Android : layout_gravity= "center_vertical"
android:text= "test"
android:textcolor= "@color/black"
android: Textsize= "18sp"/>
</LinearLayout>
Use:
int[] icons = {r.mipmap.icon_menu_item_edit, r.mipmap.icon_menu_item_delete};
string[] Texts = {"Edit", "delete"};
list<menupopwindowbean> list = new arraylist<> ();
Menupopwindowbean bean = null;
for (int i = 0; i < icons.length i++) {
bean = new Menupopwindowbean ();
Bean.seticon (Icons[i]);
Bean.settext (Texts[i]);
List.add (bean);
Menupopwindow pw = new Menupopwindow (personalimgplayactivity.this, list);
Pw.setonitemclick (Myonitemclicklistener);
Pw.showpopupwindow (Findviewbyid (R.id.img_top1_share));/Click the button in the upper right corner
The above is a small set to introduce the Android development Popwindow imitation micro-letter in the upper right corner drop-down menu Instance code, hope to help everyone, if you have any questions welcome to my message, small series will promptly reply to everyone's