PopupWindow 需要一个自定义的布局文件
列如:popupwindow.xml <?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:background="#000"
android:orientation="vertical" >
<TextView
android:textSize="25dp"
android:textColor="#ffffff"
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/start" /> <TextView
android:textSize="25dp"
android:textColor="#ffffff"
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/uninstall" /> <TextView
android:textSize="25dp"
android:textColor="#ffffff"
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/detil" /> </LinearLayout> LayoutInflater flater=LayoutInflater.from(context);
View popview=flater.inflate(R.layout.popuwindow, null);
PopupWindow popup=new PopupWindow(popview, 200, 130,true);
第一个参数:是自定义的布局文件
40 第二、三个参数:显示的宽、高
41 第四个参数:是否获得焦点
popup.showAsDropDown(view);显示在view(控件)的下面,
//创建一个自适应大小的弹出菜单
new PopupWindow(popview, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,true) //关闭popuwindow窗口
popup.dismiss(); 要想实现弹出的菜单的里面的菜单项的事件功能,就必须使用popview.findViewById(R.id.textview1)这样的方法之后才能为其添加事件监听器