警报对话框仅适用于图像

时间:2014-05-25 14:35:47

标签: android android-alertdialog android-dialog

游戏结束后我必须展示一张图片。为此,我使用警报对话框并使用缩放动画。到目前为止,我可以通过黑色设置边界的警告对话框。我只需要没有任何背景的图像。请告诉我我的代码所需的更改

public void showDialogGameOver() {      

    showToast("Game Over ! ");  
    LayoutInflater li = LayoutInflater.from(this);
    final View promptsView = li.inflate(R.layout.dialoggameover, null);
    AlertDialog.Builder alertDialogBuilder  = new AlertDialog.Builder(this); 
    alertDialogBuilder.setView(promptsView);     

    alertDialog = alertDialogBuilder.create(); 
    alertDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimationZoom;
    alertDialog.setCanceledOnTouchOutside(false);
    alertDialog.setCancelable(false); 
    alertDialog.getWindow().setBackgroundDrawable(new 
               ColorDrawable(android.graphics.Color.TRANSPARENT));
    alertDialog.show();  
}   

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试以下代码。

public class MyCustomDialog extends Dialog {

    public MyCustomDialog(Context context) {
        super(context);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        requestFeature(Window.FEATURE_NO_TITLE);
        setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.alert);
        setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));        
    }
}

参考:

  1. Extend Dialog Class Example
  2. Dialog Fragment with Transparency