I use my own dialog style to remove the white border. To do this, I created my own style, inheriting from Theme.Dialog, and set it in the dialog designer. When you don't set any style (I assume it defaults to Theme.Dialog), the dialog is centered both horizontally and vertically, but when I use my own style, which simply overrides android: windowBackground, my dialog no longer centered, so it seems that the style is not inherited ...
Can anybody help?
Thank!
My style:
<resources>
<style
name="Theme_Dialog_Translucent"
parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@color/transparent</item>
</style>
</resources>
My class:
public class CustomDialog extends Dialog implements OnClickListener {
Button okButton;
public CustomDialog(Context context) {
super(context, R.style.Theme_Dialog_Translucent);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.custom_dialog);
okButton = (Button) findViewById(R.id.button_ok);
okButton.setOnClickListener(this);
}
...
}
My layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/confirmation"
android:orientation="vertical"
android:background="@drawable/dialog_background"
android:layout_width="279dp"
android:layout_height="130dp"
>
<TextView android:id="@+id/dialog_title"
android:text="@string/dialog_title"
android:textColor="#FFF"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<TextView android:id="@+id/dialog_text"
android:text="@string/dialog_text"
android:textColor="#FFF"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<LinearLayout android:id="@+id/confirmation"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/button_ok"
android:background="@drawable/button_ok"
android:layout_width="128dp"
android:layout_height="43dp"
android:text="ok"
android:textColor="#FFFFFF"
/>
<Button android:layout_width="128dp"
android:id="@+id/button_cancel"
android:layout_height="43dp"
android:background="@drawable/button_cancel"
android:text="cancel"
android:textColor="#FFFFFF"
/>
</LinearLayout>
</LinearLayout>
source
share