4

I'm using a custom layout for an alert dialog, in which I set a custom background image.

When displayed, it seems that the dialog box is higher than my image background, while I set the layout dimensions to the image dimensions.

How can I set the dialog box dimensions to the dimensions of my background image? How can I remove this white border?

Thanks

enter image description here

dialog layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout_root"
              android:orientation="vertical"
              android:background="@drawable/whip_sel_dialog_bg"              
              android:layout_width="279dp"
              android:layout_height="130dp" >

    <TextView android:id="@+id/dialog_title"        
        android:textColor="#FFF"
        android:textSize="16sp"
        android:textStyle="bold"
        android:text="@string/dialog_title"
        android:layout_width="fill_parent" android:gravity="center" android:layout_height="30dp" android:layout_marginTop="5dp"/>

    <TextView android:id="@+id/dialog_text"     
        android:textColor="#FFF"
        android:layout_height="35dp" android:layout_width="fill_parent" android:gravity="center"/>

    <LinearLayout android:id="@+id/confirmation"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:gravity="center">

        <Button android:id="@+id/button_cancel"
            android:layout_width="128dp"
            android:layout_height="43dp"
            android:background="@drawable/btn_ok"            
            android:textColor="#FFF"
            android:text="@string/cancel"
            android:layout_marginRight="10dp"/>
        <Button android:id="@+id/button_ok"         
            android:layout_width="128dp"
            android:layout_height="43dp"
            android:background="@drawable/btn_ok"
            android:textColor="#FFF"
            android:text="@string/ok" />

    </LinearLayout>
</LinearLayout>

dialog class

public class WSelDialog extends Dialog implements OnClickListener {
    private Button okButton, cancelButton;
    public WSelDialog() {       

        super(MainActivity.this);

        setContentView(R.layout.whipem_dialog);
        okButton = (Button) findViewById(R.id.button_ok);
        okButton.setText(getString(R.string.whip_sel_ok));
        okButton.setOnClickListener(this);
        cancelButton = (Button) findViewById(R.id.button_cancel);
        cancelButton.setText(getString(R.string.whip_sel_cancel));
        cancelButton.setOnClickListener(this);
        TextView text = (TextView) findViewById(R.id.dialog_text);
        text.setText(getString(R.string.whip_sel));
        text.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        ((GlobalVars)getApplicationContext()).playSound(100);

        if (v == cancelButton)
            dismiss();
        else {
            Intent i = new Intent(MainActivity.this, WhipSelection.class);  
            startActivity(i);   
        }
    }
};
jul
  • 36,404
  • 64
  • 191
  • 318

1 Answers1

2

It looks like the dialog reserves this space for its title. See Android: How to create a Dialog without a title.

Community
  • 1
  • 1
GrAnd
  • 10,141
  • 3
  • 31
  • 43
  • It seems I can't set a custom background to Alert Dialog. – jul Mar 21 '11 at 14:30
  • @jul It the topic I mentioned there are solutions for Dialog class also. See replies with `requestWindowFeature(Window.FEATURE_NO_TITLE); ` code. – GrAnd Mar 22 '11 at 16:38