13

我正在尝试创建一个自定义多项选择警报对话框,允许用户一键选择/取消选择所有项目。我使用带有附加复选框的自定义标题来实现这一点。一切正常,除了我不知道如何使我的自定义标题看起来像默认警报对话框标题(使用相同的样式)。

这是我正在尝试做的(该示例使用Dialogs 文档中的主题。这只是一个示例,我真正想要的是应用程序主题)。

在此处输入图像描述

我为我使用的自定义标题创建了一个自定义视图,但是我不知道如何获取默认样式标题栏的属性,所以,我得到:

在此处输入图像描述

(标题下方没有蓝条,标题颜色错误)

这是我的自定义标题的布局:

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

<TextView
    android:id="@+id/title"
    style="?android:attr/textAppearanceLarge"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="Dialog title" />

<TextView
    android:id="@+id/all"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="All" />

<CheckBox
    android:id="@+id/checkBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</LinearLayout>

对我来说,我需要定义标题属性和布局的背景似乎很明显......但是自从几个小时以来我一直在爬网,搜索如何获取默认标题视图的属性。

任何想法?

4

2 回答 2

10

看看这是不是你要找的:

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


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

        <TextView
            android:id="@+id/title"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textSize="22sp"
            android:textColor="#ff33b5e5"
            android:text="Dialog title" />

        <TextView
            android:id="@+id/all"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="All" />

        <CheckBox
            android:id="@+id/checkBox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <View android:id="@+id/titleDivider"
        android:layout_width="match_parent"
        android:layout_height="2dip"
        android:background="#ff33b5e5" />

</LinearLayout>

我是如何得到这个的:

浏览到sdk硬盘上的目录 > 平台 > android-XX(例如 17)> 数据 > res > 布局 > dialog_title_holo.xml。查看带有 id 的视图titleDivider。它的背景属性:background="@android:color/holo_blue_light". 在 中查找该颜色的值res/values/colors.xml

来自styles_device_defaults.xml

<style name="TextAppearance.DeviceDefault.DialogWindowTitle" parent="TextAppearance.Holo.DialogWindowTitle" >

看着styles.xml

<style name="TextAppearance.Holo.DialogWindowTitle">
    <item name="android:textSize">22sp</item>
    <item name="android:textColor">@android:color/holo_blue_light</item>
</style>

textColor线条颜色相同。文本大小指定为22sp。而且,style="?android:attr/textAppearanceLarge"不是必需的,因为我们正在设置textSize="22sp"

<style name="TextAppearance.Large">
    <item name="android:textSize">22sp</item>
</style>
于 2013-09-01T23:11:45.983 回答
0

如果您只想使用设备默认值,而不需要自定义或扩展任何内容,您只需添加:

android:textAppearance="@android:style/TextAppearance.DeviceDefault.DialogWindowTitle"

到您的 xml 布局中的标题视图。这将根据设备主题显示不同的样式。

如果您总是想显示蓝色(全息主题)标题,无论设备默认设置如何,您都可以添加:

android:textAppearance="@android:style/TextAppearance.Holo.DialogWindowTitle"

反而。

于 2016-04-01T21:00:06.097 回答