1. 程式人生 > >如何實現dialog彈出,但activity介面顏色不變暗

如何實現dialog彈出,但activity介面顏色不變暗

// 幫助彈出的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();
   }
  });
 }