Я использую собственный стиль диалога, чтобы удалить белую рамку.Для этого я создал собственный стиль, унаследованный от Theme.Dialog, и установил его в конструкторе диалогов.Если не устанавливать какой-либо стиль (я думаю, что по умолчанию используется Theme.Dialog), диалог центрируется как по горизонтали, так и по вертикали, но когда я использую свой стиль, который просто переопределяет android: windowBackground, мой диалог больше не центрируется, поэтому кажется, чточто стиль не наследуется ...
Кто-нибудь может помочь?
Спасибо!
Мой стиль:
<resources>
<style
name="Theme_Dialog_Translucent"
parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@color/transparent</item>
</style>
</resources>
Мой класс:
public class CustomDialog extends Dialog implements OnClickListener {
Button okButton;
public CustomDialog(Context context) {
//super(context); //if I use that the dialog is centered
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);
}
...
}
Мой макет:
<?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>