Android: how to create a transparent dialog-themed activity

前端 未结 6 1306
清歌不尽
清歌不尽 2020-12-03 05:04

My original goal here was a modal dialog, but you know, Android didn\'t support this type of dialog. Alternatively, building a dialog-themed activity would possibly work.

6条回答
  •  误落风尘
    2020-12-03 05:55

    Just a quick update on @user824330 answer. Since you have the AlertDialog.Builder class, why not using it properly? Many methods are now deprecated. The up-to-date code would be similar to this:

    public class DialogActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("title")
           .setMessage("message")
           .setIcon(R.drawable.ic_launcher)
           .setPositiveButton("Yes", new OnClickListener() {
                   @Override
                   public void onClick(DialogInterface dialog, int which) {}
           })
           .setNegativeButton("No", new OnClickListener() {
                   @Override
                   public void onClick(DialogInterface dialog, int which) {}
           });
    
        final AlertDialog dialog = builder.create();
        dialog.show();
    }
    

    }

提交回复
热议问题