# Custom AlertDialog box

**URL:** https://discourse.processing.org/t/custom-alertdialog-box/14588
**Category:** Processing for Android
**Created:** [October 10, 2019, 10:01pm UTC](https://discourse.processing.org/t/custom-alertdialog-box/14588 "2019-10-10T22:01:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [October 10, 2019, 10:01pm UTC](https://discourse.processing.org/t/custom-alertdialog-box/14588/1 "2019-10-10T22:01:35Z")

</div>

Hi.  
The code below will popup a dialog box, giving the option to continue or end the program.  
I want to customize the box using a text view.  
The uncommented setting does however not work.  
How can I link this?

```auto
import processing.core.PApplet;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.widget.TextView;
import android.view.Gravity;

Activity act;
TextView msg;

void setup() {
  background(0);
  textSize(38);
  textAlign(CENTER);
  text("Click on screen", width/2, height/2);
}

void draw(){
}  

void dialogBox() {
  act = this.getActivity();
  
  TextView msg = new TextView(act); 
  msg.setText("I am a Custom Dialog Box."); 
  msg.setGravity(Gravity.CENTER_HORIZONTAL); 
  msg.setTextColor(Color.BLACK); 
  
  act.runOnUiThread(new Runnable() {
    public void run() {
      new AlertDialog.Builder(act)
        //.setView(msg)
        .setTitle("Do you want to quit?")
        .setPositiveButton("NO", 
        new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, 
          int which) {
        }
      }
      )
      .setNegativeButton("YES", 
        new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, 
          int which) {
          act.finish();
        }
      }
      )
      .show();
    }
  }
  );
}

void mousePressed(){
  dialogBox();
}

```

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [October 11, 2019, 8:39pm UTC](https://discourse.processing.org/t/custom-alertdialog-box/14588/2 "2019-10-11T20:39:32Z")

</div>

Well, here’s how:

```auto
import processing.core.PApplet;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.widget.TextView;
import android.view.Gravity;

Activity act;
TextView msg;
int msgId;

void setup() {
  background(0);
  textSize(38);
  textAlign(CENTER);
  text("Click on screen", width/2, height/2);
}

void draw() {
}  

void dialogBox() {
  act = this.getActivity();

  final TextView msg = new TextView(act); 
  msg.setBackgroundColor(Color.BLUE);
  msg.setTextSize(32);
  msg.setText("I am a Custom Dialog Box."); 
  msg.setGravity(Gravity.CENTER_HORIZONTAL); 
  msg.setTextColor(Color.WHITE); 

  act.runOnUiThread(new Runnable() {
    public void run() {
      AlertDialog.Builder builder = new AlertDialog.Builder(act);
      builder.setView(msg);
      builder.setTitle("Do you want to quit?");
      builder.setPositiveButton("NO", 
        new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, 
          int which) {
        }
      }
      );
      builder.setNegativeButton("YES", 
        new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, 
          int which) {
          act.finish();
        }
      }
      )
      .show();
    }
  }
  );
}

void mousePressed() {
  dialogBox();
}

```
