Android TimePickerDialog样式指南/文档? [英] Android TimePickerDialog styling guide/docs?

查看:136
本文介绍了Android TimePickerDialog样式指南/文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为sdk 21+(棒棒糖)设置TimePickerDialog的样式.到目前为止,我已经弄清楚了如何在XML中更改默认的colorcheme:

I'm trying to style a TimePickerDialog for sdk 21+ (Lollipop). So far I've figured out how to change the default colorscheme in XML:

<style name="TimePickerTheme" parent="@style/Theme.AppCompat.Light.Dialog">
    <item name="colorPrimary">#ff2d6073</item> <!-- no effect -->
    <item name="colorPrimaryDark">#ff2d6073</item> <!-- no effect -->
    <item name="colorAccent">#ff2d6073</item>
    <item name="android:textColor">#ffD0D102</item>
    <item name="android:textColorPrimary">#ffD0D102</item>
</style>

这可行,但是我正在寻找有关我可以更改的所有属性的指南或文档.

This works but I'm looking for a guide or documentation for all the properties I can change.

  • AccentColor执行基本的配色方案
  • TextColorPrimary做文本颜色

但是,例如,我需要在对话框的标题"(显示当前选定时间的地方)中更改大文本是什么属性?

But what property, for example, do I need to change the big text in the 'header' of the dialog (where the current selected time is displayed)?

是否有一些文档列出了您可以更改的所有可能内容?

Is there some documentation that lists all the possible things you can change?

推荐答案

在研究了AOSP主题和样式xml文件并进行了大量的搜索之后,我取得了一些进步.我现在可以为大多数(!)样式设置样式.

After digging through the AOSP theme and style xml files and a lot of googling I made some progress. I am now able to style most(!) things.

所以这是部分答案,还没有完全解决.但是,这是我走了多远:

So this is a partial answer, not all the way there yet. But here's how far I got:

您可以看到我现在可以将标题,未选择的时间部分(在这种情况下为分钟),圆圈,该圆圈中的数字和手"(或选择器)作为主题.哦,按钮的样式也一样.

You can see that I'm now able to theme the header, the un(!)selected time part (minutes in this case), the circle, the numbers in that circle and the 'hand' (or selector). Oh, and the buttons are styled, too.

首先让我解释一下我是如何工作的:重要的是,您不能直接从应用程序的主题或(警报)对话框主题/样式中覆盖内容.可以这么说,您必须从一个跳到另一个.

Let me explain how I got things working, first: the important thing is that you can't override things directly from you app's theme OR from a (alert)dialog theme/style. You have to go from one to the next, so to speak.

示例:

AndroidManifest.xml::为应用和/或活动设置自定义主题

AndroidManifest.xml: Set custom theme for app and/or activity

<activity>
    android:theme="@style/Theme.MyTheme" 
</activity>

values-v21/styles.xml:(您的自定义主题所在的位置):设置timePickerDialogTheme

values-v21/styles.xml: (where your custom theme resides): set the timePickerDialogTheme

<style name="Theme.MyTheme" parent="@style/Theme.AppCompat.Light">
    <item name="android:timePickerDialogTheme">@style/TimePickerDialogTheme</item>
</style>

然后在其下,定义timePickerDialogTheme并设置timePickerStyle:

Then below that, define the timePickerDialogTheme and set the timePickerStyle:

<style name="TimePickerDialogTheme" parent="@style/Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#ff2d6073</item> <!-- colorAccent here seems to work just fine? -->
    <item name="android:timePickerStyle">@style/TimePickerDialogStyle</item> 
</style>

现在您可以在此处定义大多数样式.

Now you can define most of the styling here..

<style name="TimePickerDialogStyle" parent="@android:style/Widget.Material.Light.TimePicker">

    <item name="colorAccent">#ff2d6073</item> <!-- colorAccent here seems to work just fine? -->

    <item name="android:timePickerMode">clock</item>
    <item name="android:headerBackground">#ff2d6073</item>
    <item name="android:headerTimeTextAppearance">@style/TextAppearance.TimePickerDialogStyle.TimeLabel</item> <!-- TimePicker Time *TextAppearance* -->
    <item name="android:numbersTextColor">#ff000000</item>
    <item name="android:numbersSelectorColor">#ff2d6073</item>
    <item name="android:numbersBackgroundColor">#ffdddddd</item>

</style>

上面重要的一行是:

<item name="android:headerTimeTextAppearance">@style/TextAppearance.TimePickerDialogStyle.TimeLabel</item>

因为如果要在标题中设置文本样式(时间,时间,实际上),则需要定义headerTimeTextAppearance:

Because if you want to style the text (well, time, actually) in the header you need to define the headerTimeTextAppearance:

<style name="TextAppearance.TimePickerDialogStyle.TimeLabel" parent="@android:style/TextAppearance.Material">

    <item name="android:textSize">60sp</item> <!-- from -->
    <item name="android:textColor">#ffD0D102</item>

</style>

现在,如果您看一下 Widget.Material.TimePicker (按住ctrl -f'timepicker'直到找到它),您会注意到许多其他属性,您应该可以对其进行修改:

Now, if you take a look at the Widget.Material.TimePicker in AOSP styles.xml (ctrl-f 'timepicker' until you find it) you'll notice a bunch of other properties that you should be able to modify:

headerTimeTextAppearance
headerAmPmTextAppearance
headerSelectedTextColor
headerBackground
numbersTextColor
numbersBackgroundColor
amPmTextColor
amPmBackgroundColor
amPmSelectedBackgroundColor
numbersSelectorColor

大多数这些工作(只要您为每个对象加上"android:"),但我无法使"headerSelectedTextColor"正常工作.我收到一个编译错误,说无法匹配属性bla bla".另外,如果您看一下上面的示例,由于'@ dimen/timepicker_ampm_label_size'值引发了错误,我为'headerTimeTextAppearance'属性硬编码了textSize.

Most of these work (as long as you prepend 'android:' for each of them) BUT I could not get 'headerSelectedTextColor' to work. I got a compile error saying something like "could not match property bla bla". Also, if you look at my example above, I hardcoded the textSize for the 'headerTimeTextAppearance' property because the '@dimen/timepicker_ampm_label_size' value threw errors.

简而言之:上面列出了大多数内容以及如何使它们工作.但并非所有人都清楚.所以我仍然会看到完整的文档/指南:)

In short: most of the things are listed above and how to get them working. But not all is clear. So I'd still see that complete documentation/guide :)

这篇关于Android TimePickerDialog样式指南/文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆