Android,如何更改自定义对话框中标题的颜色?

时间:2011-12-01 03:29:53

标签: android colors header customdialog

我读了Custom dialog on Android: How can I center its title?但是android不知道parent="@android:style/DialogWindowTitle

我将对话框样式更改为:

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

在我写的代码中:

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

每件事都没问题,我有自定义对话框。但我有一个问题: 我在样式中作为属性引入的背景颜色将填充所有对话框。我需要这种颜色只用在标题中。我在R.layout.inf_dialoglayout

中定义了另一种背景颜色

感谢

更新 “R.layout.inf_dialoglayout”的XML文件:

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

最后app的截图: enter image description here

1 个答案:

答案 0 :(得分:0)

您可以尝试使用此xml我已经更改了xml一点

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