您的位置:首页 > 移动开发 > Android开发

如何实现dialog弹出,但activity界面颜色不变暗

2014-09-28 16:59 399 查看
// 帮助弹出的dialog
protected void helpDialog() {
AlertDialog.Builder builder = new Builder(CyjlActivity.this);
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.dialog_cyjl_help, null);
final AlertDialog cyjlHelpDialog = new AlertDialog.Builder(this)
.setView(layout).create();
cyjlHelpDialog.show();
//这些是设置对话框大小,位置,下面activity的亮度
WindowManager.LayoutParams params = cyjlHelpDialog.getWindow()
.getAttributes();
params.width = 450;
params.height = 300;
params.gravity = Gravity.CENTER
//alpha在0.0f到1.0f之间。1.0完全不透明,0.0f完全透明,自身不可见。
params.alpha=1.0f;

// 这个是设置activity的亮度的dimAmount在0.0f和1.0f之间,0.0f完全不暗,即背景是可见的 ,1.0f时候,背景全部变黑暗。
// params.dimAmount = 0f;
// 设置对话框的布局参数为居中
cyjlHelpDialog.getWindow().setAttributes(params);
//这句话把dialog设置成了模态形式,即点击dialog外面的部分不变色
cyjlHelpDialog.setCanceledOnTouchOutside(false);
cyjlHelpDialog.setCancelable(true);// 这个决定按了返回键是否可以退出,默认是true可以退出
Button button = (Button) layout.findViewById(R.id.cyjl_yzgz_fanhui);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
cyjlHelpDialog.cancel();
}
});
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐