dialog底部自动弹出

/**
* 自定义弹出框 默认打开 动画效果为从底部弹出

* public void showPopWindow() {
MobclickAgent.onEvent(MainA.this, "CLICK_ME");// 点我
if (MyApplication.getPerferenceUtil().containKey(Constant.SCHEDULE_STATUS)) {
Text_chooseCar.setText("正在订车");
} else {
Text_chooseCar.setText("快捷订车");
}
if (dialog == null) {
dialog = MyTools.showAutoDialog(MainA.this, tab6View, Gravity.BOTTOM, 0.0, 0.0);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
} else {
dialog.show();
}
}


*/
public static Dialog showAutoDialog(Activity context, View view, int position, double width, double height) {
android.app.AlertDialog dialog = new android.app.AlertDialog.Builder(context).create();


if (MyTools.isRunningForeground(context)) {
dialog.show();
}


// 关键在下面的两行,使用window.setContentView,替换整个对话框窗口的布局
Window window = dialog.getWindow();
window.setContentView(view);
window.setGravity(position); // 此处可以设置dialog显示的位置
// 对dialog的窗口大小进行设置
WindowManager m = context.getWindowManager();
Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
WindowManager.LayoutParams p = window.getAttributes(); // 获取对话框当前的参数值
if (width != 0.0) {
p.width = (int) (d.getWidth() * width);
} else {
p.width = (int) d.getWidth();
}
if (height != 0.0) {
p.height = (int) (d.getHeight() * height);
}
window.setAttributes(p);
if (position == Gravity.BOTTOM) {


window.setWindowAnimations(R.style.c_anim_move_bt);
}


return dialog;
}

你可能感兴趣的:(Android移动开发)