自定义警报对话框问题

时间:2011-03-21 12:10:32

标签: android dialog

我正在为警报对话框使用自定义布局,我在其中设置了自定义背景图像。

显示时,似乎对话框高于我的图像背景,而我将布局尺寸设置为图像尺寸。

如何将对话框尺寸设置为背景图像的尺寸?如何删除此白色边框?

由于

enter image description here

对话框布局

<?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>

对话框类

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);   
        }
    }
};

1 个答案:

答案 0 :(得分:2)

看起来对话框为其标题保留了这个空间。请参阅Android: How to create a Dialog without a title