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);   
        }
    }
};
4
  • How is WipSelection declared in AndoirdManifest.xml Commented Mar 21, 2011 at 12:17
  • what is background image's height or width..? Commented Mar 21, 2011 at 12:20
  • @Mojo Risin: <activity android:name=".WhipSelection" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:screenOrientation="portrait" /> Commented Mar 21, 2011 at 12:52
  • @CapDroid: 279px X 130px. I set the dimensions of the LinearLayout to these dimensions. Commented Mar 21, 2011 at 12:54

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

It seems I can't set a custom background to Alert Dialog.
@jul It the topic I mentioned there are solutions for Dialog class also. See replies with requestWindowFeature(Window.FEATURE_NO_TITLE); code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.