1.自写一个dialog
public class MyDialog extends Dialog {
privatefinal static String TAG="class MyDialog";
privateWindow window = null;
publicMyDialog(Context context, boolean cancelable,
OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
// TODOAuto-generated constructor stub
}
publicMyDialog(Context context, int theme) {
super(context, theme);
// TODOAuto-generated constructor stub
}
publicMyDialog(Context context) {
super(context);
// TODOAuto-generated constructor stub
}
public voidsetView(View view){
setContentView(view);
}
public voidsetView(int id){
setContentView(id);
}
public voidsetProperty(int x,int y,int w,int h) {
window =getWindow();// 得到对话框的窗口.
WindowManager.LayoutParams wl = window.getAttributes();
wl.x = x;//这两句设置了对话框的位置.0为中间
wl.y =y;
wl.width =w;
wl.height =h;
wl.alpha =0.6f;// 这句设置了对话框的透明度
// wl.dimAmount=0.0f; //设置黑暗度
wl.gravity =Gravity.TOP | Gravity.LEFT;
window.setAttributes(wl);
}
}
2.在style.xml中添加此dialog的样式
3.对dialog的使用
<?xml version="1.0"encoding="utf-8"?>
<resources>
<style name="progress_dialog"parent="@android:style/Theme.Dialog">
<!--弹出框的背景,可以自己做一张图片命名为panel_background.9.png-->
<itemname="android:windowBackground">@drawable/panel_background</item>
<itemname="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<itemname="android:windowFrame">@null</item><!--边框-->
<itemname="android:windowIsFloating">true</item><!--是否浮现在activity之上-->
<itemname="android:windowIsTranslucent">false</item><!--半透明-->
<itemname="android:windowNoTitle">true</item><!--无标题-->
<itemname="android:backgroundDimEnabled">false</item><!--模糊-->
</style>
</resources>
3.对dialog的使用
MyDialog md=newMyDialog(BSMINIActivity.activity,R.style.progress_dialog);
md.setView(list1);//添加一个ListView在此dialog中
md.setProperty(0, 0, 300, 300);//设置坐标和宽高
md.setCanceledOnTouchOutside(true);//设置点击非dialog区域时取消此dialog
md.show();//显示