tags:

views:

1801

answers:

1

I want to have a dialog containing 3 views 1. title with black background 2. some body text white background 3. a line with 2 buttons with gray background.

The problem is that i want the background color of the body to be WHITE, but even my view has set backgroundcolor to WHITE, there seems to be some margins at top and bottom of the body that got a diffrent background color.

       TextView title = new TextView(this);
    title.setText("This is my title");
    title.setBackgroundColor(Color.BLACK);
    title.setPadding(10, 10, 10,10);
    title.setGravity(Gravity.CENTER);
    title.setTextColor(Color.WHITE);
    title.setTextSize(20);

    TextView view = new TextView(this);
    view.setText("Lorem Ipsum blabla bla \n more bla bla aha hhahah blablalblal.");
    view.setBackgroundColor(Color.WHITE);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(false);
    builder.setCustomTitle(title);
    builder.setView(view);
    builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                    Bingo.this.finish();
               }
           })
           .setNegativeButton("No", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
               }
           });
    AlertDialog alert = builder.create();
    alert.show();
    ((View)view.getParent()).setBackgroundColor(Color.WHITE);  // <-- UGLY fix to avoid stupid margins at top and bottom of the body...

Any ideas how i can remove the last line of the code the "UGLY fix" ?

+1  A: 

To fix the background color problem i just set

builder.setInverseBackgroundForced(true);

so my complete code is

View view = View.inflate(this, R.layout.tos_dialog, null);

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setIcon(R.drawable.icon);
builder.setTitle("Bla bla title");
builder.setView(view);
builder.setInverseBackgroundForced(true);
builder.setPositiveButton("I agree", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
       }
   });
builder.setNegativeButton("I don't agree", new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog, int id) {
          Bingo.this.finish();
       }
    });
AlertDialog alert = builder.create();
alert.show();

and the inflated xml for the view with text with autolinks

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/root" 
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="10px"
android:textColor="#000"
android:gravity="left"
android:textSize="14px"
android:background="#FFF"
android:autoLink="all"
android:textColorLink="#00F"
android:text="bla bla http://stackoverflow.com is cool, bla bla."
/>
PHP_Jedi