Android: how to create a transparent dialog-themed activity

前端 未结 6 1313
清歌不尽
清歌不尽 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:50

    You can create a tranparent dialog by this.

    public class DialogActivity extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
            alertDialog.setTitle(" ");
            alertDialog.setMessage("");
            alertDialog.setIcon(R.drawable.icon);
            alertDialog.setButton("Accept", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {                
                }
            });
            alertDialog.setButton2("Deny", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            alertDialog.show();
        }
    }
    

    After this just put a line in AndroidManifest.xml, where you define your activity in manifest.

    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    

提交回复
热议问题