0

i am trying to present an alertdialog in my actvitiy which describe if the user doesnot have some information stored in my database then a alertdialog will popup in front of the user with button. here is my code for the dialog in activity

AlertDialog.Builder myAlert= new AlertDialog.Builder(this);
myAlert.setMessage("You are winner!").setPositiveButton("Continue...", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {

    }
})
.setTitle("Welcome")
.create();
myAlert.show();

so basicly i am not getting the desired alertdialog i wanted,i am getting something like this enter image description here.

i have no borders between title and message and button, my button not placed at center as default ,what should i do to fix these i have tried many videos and posts.

ThomasThiebaud
  • 11,331
  • 6
  • 54
  • 77

3 Answers3

2

i have no borders between title and message and button, my button not placed at center as default ,what should i do to fix these i have tried many videos and posts.

In case, if you don't like the material dialog and you want to platform's specific dialog then you should use android.app.AlertDialog in place of android.support.v7.app.AlertDialog.

Change the import statement from android.support.v7.app.AlertDialog to android.app.AlertDialog

But I recommend you go with material dialog box.

Rahul Chaurasia
  • 1,601
  • 2
  • 18
  • 37
1

You should use custom dialog for this purpose. Create a custom layout. And setlayoutview to the dialog.

sample code

button = (Button) findViewById(R.id.buttonShowCustomDialog);

    // add button listener
    button.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View arg0) {

        // custom dialog
        final Dialog dialog = new Dialog(context);
        dialog.setContentView(R.layout.custom);
        dialog.setTitle("Title...");

        // set the custom dialog components - text, image and button
        TextView text = (TextView) dialog.findViewById(R.id.text);
        text.setText("Android custom dialog example!");
        ImageView image = (ImageView) dialog.findViewById(R.id.image);
        image.setImageResource(R.drawable.ic_launcher);

        Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
        // if button is clicked, close the custom dialog
        dialogButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
      }
    });

See details at below link

http://www.mkyong.com/android/android-custom-dialog-example/

Zahan Safallwa
  • 3,880
  • 2
  • 25
  • 32
0

Try this:

 AlertDialog.Builder myAlert= new AlertDialog.Builder(this, android.R.style.Theme_Holo_Light_Dialog);

    myAlert.setTitle("Welcome")
.setMessage("You are winner!")
           .setCancelable(false)
           .setPositiveButton("Continue...", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                    //do things
               }
           });
    AlertDialog alert = myAlert.create();
    alert.show();
Jas
  • 3,207
  • 2
  • 15
  • 45
  • i tried to use your line of code instead it just present the same dialog in full screen. – Ibrahim Shalhoub Oct 13 '15 at 12:29
  • it opened the dialog in full screen and not like pop up in the picture i uploaded. – Ibrahim Shalhoub Oct 13 '15 at 12:34
  • Then you have to check the sdk version you are using and the adt version – Jas Oct 13 '15 at 12:36
  • android { compileSdkVersion 23 buildToolsVersion '23.0.1' defaultConfig { applicationId "com.example.barhom.waves" minSdkVersion 11 targetSdkVersion 23 versionCode 1 versionName "1.0" } been stuck in this problem for 1 day i canot solve it ... – Ibrahim Shalhoub Oct 13 '15 at 12:45
  • https://www.dropbox.com/s/swz9so6botv6toc/Screenshot_2015-10-13-15-57-26.png?dl=0 i am trying different themes but not getting the right results , i am still seeing the dialogbox with no borders between title and message and button. – Ibrahim Shalhoub Oct 13 '15 at 13:05