Issue with inherited style in Android
I'm using a custom dialog style to remove the white border. To achieve this, I created a custom style inheriting from Theme.Dialog, and set it in the dialog constructor. When not setting any style (I guess it takes Theme.Dialog as default), the dialog is centered both horizontally and vertically, but when I use my style, which just override android:windowBackground, my dialog is not centered anymore, so it seems that the style is not inherited...
Anybody can help?
Thanks!
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); //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);
}
...
}
My layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xml开发者_如何学Gons: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>
精彩评论