【问题标题】:Android, How can I change the color of header in my Custom dialog?Android,如何更改自定义对话框中标题的颜色?
【发布时间】:2011-12-01 13:35:23
【问题描述】:

我读过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>

最后是应用程序的屏幕截图:

【问题讨论】:

  • 你能告诉我们xml文件inf_dialoglayout
  • 所以您希望您的确认字段更改其背景颜色或其他内容

标签: android colors header customdialog


【解决方案1】:

你可以试试这个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>

【讨论】:

  • 我希望这对你有帮助你可以改变标题背景颜色
  • 感谢亲爱的 Raghav,您建议的代码更改了正文而不是标题的颜色。但我可以通过样式更改标题。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-22
  • 2014-02-15
  • 1970-01-01
  • 2015-04-05
  • 1970-01-01
相关资源
最近更新 更多