0

I am trying to implement AlertDialog based on DialogFragment with this code:

public class AlertDialogFragment extends DialogFragment {
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return new AlertDialog.Builder(getActivity())
                .setTitle("title")
                .setMessage("message")
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                })
                .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                })
                .create();
    }
}

It working well, but I get a strange white border around AlertDialog:

enter image description here

How to remove this border (preferably programmatically)?

UPDATE: my styles.xml contains this code:

<style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:alertDialogTheme">@style/MyDialogTheme</item>
</style>        

<style name="MyDialogTheme" parent="@android:style/Theme.Holo.Light.Dialog"></style>

When I remove <item name="android:alertDialogTheme">@style/MyDialogTheme</item> row, this issue is gone away. But I need this row because I want to customize AlertDialog. How to fix this style?

BArtWell
  • 4,176
  • 10
  • 63
  • 106

1 Answers1

-1

I have just checked your code ,but have not get any issue like this. I call the class like

   package com.example.test;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.widget.Toast;

public class A extends FragmentActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);



        AlertDialogFragment al=new AlertDialogFragment();
        FragmentManager fm = getSupportFragmentManager();
        al.show(fm, "test");


    }


class AlertDialogFragment extends DialogFragment {
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            return new AlertDialog.Builder(getActivity())
                    .setTitle("title")
                    .setMessage("message")
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    })
                    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    })
                    .create();
        }
    }

}
  • use new support library http://developer.android.com/reference/android/support/v7/app/AlertDialog.html – Ajeet47 Apr 27 '15 at 13:11