Android的对话框有两种:PopupWindow和AlertDialog。它们的不同点在于:
AlertDialog的位置固定,而PopupWindow的位置可以随意
AlertDialog是非阻塞线程的,而PopupWindow是阻塞线程
popupwindow 新建步骤:
//弹出框所属XML的ID
View popupWindow_view = getLayoutInflater().inflate(R.layout.pop, null,
false);
ContentListView muluListView= (ContentListView) popupWindow_view.findViewById(R.id.zb_listView);
//显示提供了两种形式
public void showAsDropDown(View anchor, int xoff, int yoff, int gravity)
public void showAtLocation(View parent, int gravity, int x, int y)
//注意:没有设置backgroundDrawable的话,弹出的窗口不会消失 popupWindow.setBackgroundDrawable(new BitmapDrawable());
如果要设置弹出框的样式可以在android:background="@drawable/xml"中设置背景
例如:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#80065e8d" /> <stroke android:width="1dp" android:color="#363636" /> <gradient android:endColor="#7A7A7A" android:startColor="#7A7A7A" /> <padding android:bottom="7dp" android:left="7dp" android:right="7dp" android:top="7dp" /> <corners android:radius="10dp" /> </shape>
注意<solid android:color="#80065e8d" />可以设置背景半透明
</pre>