18

Why am i getting this white background under my alert dialogbox. I been trying to figure out the problem for an hour and had no luck. Can someone please help me?

Also, why is that the left and right sides of the title has a little dark shade.

enter image description here

protected void onPostExecute(String result) {
    //progressDialog.dismiss();
    try {
        JSONObject json = new JSONObject(result);
        String status = json.getString("status");
        String message = json.getString("message");
        if(status.equals("true")) {
            Intent intent = new Intent(context, HomeActivity.class);
            intent.putExtra(LoginActivity.EXTRA_MESSAGE, status);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }
        else{
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setMessage(message)
                   .setTitle("Error")
                   .setNeutralButton("OK", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int which) {
                           dialog.cancel();
                       }
                   }).create().show();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Drunken Daddy
  • 7,326
  • 14
  • 70
  • 104

4 Answers4

29

Import android.support.v7.app.AlertDialog instead of android.app.AlertDialog

Sheychan
  • 2,415
  • 14
  • 32
14

Change your code as -

 Dialog alertDialog = new Dialog(this);
    alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    alertDialog.setContentView(R.layout.tabs);
    alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    alertDialog.show();

Or you can add theme to your existing code.

AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
Ravi Bhandari
  • 4,682
  • 8
  • 40
  • 68
7

When initializing dialog builder, pass second parameter as the theme. So Change

AlertDialog.Builder builder = new AlertDialog.Builder(activity);

to

AlertDialog.Builder builder = new AlertDialog.Builder(activity, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);

It is old answer, now

Import android.support.v7.app.AlertDialog instead of android.app.AlertDialog

as given in accepted answer.

Community
  • 1
  • 1
Giru Bhai
  • 14,370
  • 5
  • 46
  • 74
6

if you can access Dialog class, try this:

 alertDialog.getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);    

before:

dialog_before

after:

dialog_after

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
id3210
  • 81
  • 1
  • 3