Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

white background under alert dialog box

Tags:

android

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();
    }
}
like image 485
Drunken Daddy Avatar asked Apr 14 '15 11:04

Drunken Daddy


People also ask

How do I make alert dialog background transparent?

setBackgroundColor(Color. TRANSPARENT); wv. setPadding(5, 25, 5, 0); ImageView imgcartl=(ImageView)layout.

What will be the background color of the following alert dialog snippet?

on your dialog builder. It will force the background to white color (instead of dark grey) on android version before Froyo.


3 Answers

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

like image 57
Sheychan Avatar answered Oct 13 '22 01:10

Sheychan


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);
like image 22
Ravi Bhandari Avatar answered Oct 13 '22 01:10

Ravi Bhandari


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.

like image 30
Giru Bhai Avatar answered Oct 12 '22 23:10

Giru Bhai