我想更改AlertDialog(Holo主题)中蓝色标题和蓝线的颜色,通过查看android styles.xml和themes.xml,我能够更改标题的颜色,但是我找不到任何属性或样式我可以使用/更改以更改XML的颜色。

以下是我用来更改标题颜色的样式

<style name="myAlertDialog" parent="android:Theme.Holo.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowTitleStyle">@style/myAlertDialogTitleStyle</item>
</style>

<style name="myAlertDialogTitleStyle">
    <item name="android:maxLines">1</item>
    <item name="android:scrollHorizontally">true</item>
    <item name="android:textAppearance">@style/myAlertDialogTitleStyleTextAppearance</item>
</style>

<style name="myAlertDialogTitleStyleTextAppearance">
    <item name="android:textSize">22sp</item>
    <item name="android:textColor">#ffff8800</item>
</style>

最佳答案

编辑:我在原始答案中输入错误。

不幸的是用于对话框的样式是内部的,不能以与其他一些易于操作的holo元素相同的方式使用I have created an open source project for dealing with this in very simple situations(我希望将其扩展到更多,并使其更合法)。这是指向新答案的链接,可以更深入地解决这个问题:How can I change the color of AlertDialog title and the color of the line under it

为了后代,这是我天真的旧答案:

查看answer posted here。对于您的特定目标,您需要覆盖dialogTitleDecorLayout样式(我认为是!),而不是listSeparatorTextViewStyle样式。

如果您对最初设置的位置感到好奇,可以在计算机上android sdk文件夹中浏览themes.xml文件,然后搜索dialogTitleDecorLayout属性。这将导致您找到一个dialog_title_holo布局文件,该文件也应位于您的计算机上。在那里,您应该在布局内找到以下代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:fitsSystemWindows="true">
  <TextView android:id="@android:id/title" style="?android:attr/windowTitleStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="60dip"
    android:paddingLeft="32dip"
    android:paddingRight="32dip"
    android:gravity="center_vertical|left" />
  <ImageView android:id="@+id/titleDivider"
        android:layout_width="match_parent"
        android:layout_height="4dip"
        android:scaleType="fitXY"
        android:gravity="fill_horizontal"
        android:paddingLeft="16dip"
        android:paddingRight="16dip"
        android:src="@android:drawable/divider_strong_holo" />
  <FrameLayout
    android:layout_width="match_parent" android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="vertical"
    android:foreground="?android:attr/windowContentOverlay">
    <FrameLayout android:id="@android:id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
  </FrameLayout>
</LinearLayout>

注意的代码是@android:drawable/divider_strong_holo参考。该文件也存在于您的计算机上,应该是蓝色的9patch。您将需要创建不同颜色的类似9patch。祝好运!即使这不是正确的属性,我想您也会在这里看到需要做的...

08-18 15:23
查看更多