2

I read Custom dialog on Android: How can I center its title? but android doesn't know parent="@android:style/DialogWindowTitle.

I changed dialog style to:

<style name="customDialogStyle" parent="@android:style/Theme.Dialog">
        <item name="android:gravity">center_horizontal</item>
        <item name="android:textSize">25dip</item>
        <item name="android:textStyle">bold</item>
        <item name="android:background">#04a9ee</item>
    </style>

and in code i have written:

dialog = new Dialog(Inf_PackageActivity.this, R.style.customDialogStyle);
        dialog.setTitle("Confirmation");
        dialog.setContentView(R.layout.inf_dialoglayout);

Every thing is ok and i have my custom dialog. but i have an issues: The background color that I introduce in style as an attribute will fill all the dialog. I need this color just be used in Header. I have defined another background color in R.layout.inf_dialoglayout

thanks

Update: XML file of "R.layout.inf_dialoglayout":

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="250dip"
    android:layout_height="150dip"
    android:orientation="vertical" >

    <View
        android:layout_width="wrap_content"
        android:layout_height="3dp"
        android:background="@drawable/separator" />

    <TextView 
        android:text="Are you sure you want this package?" 
        style="@style/dialog.description"
        android:paddingTop="10dip"
        android:paddingBottom="13dip" />

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center" >

        <Button 
            android:text="Yes!" 
            android:id="@+id/btnAccept" 
            android:background="@drawable/btngradient" 
            style="@style/ButtonText.Smaller" />

        <Button
            android:text="No!"
            android:id="@+id/btnReject"
            android:background="@drawable/btngradient"
            style="@style/ButtonText.Smaller" />
    </LinearLayout>
</LinearLayout>

and finally Screenshot of app: enter image description here

Community
  • 1
  • 1
Hesam
  • 52,260
  • 74
  • 224
  • 365

1 Answers1

0

You can try with this xml i have changed the xml little bit

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dip"
android:layout_height="150dip"
android:orientation="vertical" >

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dip"
android:layout_height="150dip"
android:orientation="vertical" 
android:background=" colou u want here in ur title " >

<View
    android:layout_width="wrap_content"
    android:layout_height="3dp"
    android:background="@drawable/separator" />

</LinearLayout>

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dip"
android:layout_height="150dip"
android:orientation="vertical" >
<TextView 
    android:text="Are you sure you want this package?" 
    style="@style/dialog.description"
    android:paddingTop="10dip"
    android:paddingBottom="13dip" />
</LinearLayout>

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dip"
android:layout_height="150dip"
android:orientation="vertical" >
<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_gravity="center" >
    <Button 
        android:text="Yes!" 
        android:id="@+id/btnAccept" 
        android:background="@drawable/btngradient" 
        style="@style/ButtonText.Smaller" />

    <Button
        android:text="No!"
        android:id="@+id/btnReject"
        android:background="@drawable/btngradient"
        style="@style/ButtonText.Smaller" />
        </LinearLayout>
</LinearLayout>
</LinearLayout>
Raghav Chopra
  • 527
  • 1
  • 10
  • 26
  • i hope this would be helpful for u you can change title background colour – Raghav Chopra Dec 01 '11 at 05:36
  • 1
    Thanks dear Raghav, the code that you suggested changed the color of body not header. But I can change the header through style. Thanks for your help. – Hesam Dec 01 '11 at 06:08