如何自定义TimePicker在材料设计的Andr​​oid? [英] How to customize TimePicker in material design android?

查看:330
本文介绍了如何自定义TimePicker在材料设计的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法改变选择颜色和TimePicker的其他部分。
到目前为止,我可以改变头颜色和背景,但我无法改变innercircle和文本颜色。

更改自定义主题<一个href=\"https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B3321sZLoP_HcVRNejI4UTh6aHM/components_pickers_time1.png\"相对=nofollow>链接。

我的code:

 &LT; TimePicker
    机器人:ID =@ + ID / TP
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:timePickerMode =时钟
    机器人:headerBackground =#565466
    机器人:amPmBackgroundColor =#500126
    机器人:numbersBackgroundColor =#57e326
    机器人:numbersTextColor =#995394
    机器人:numbersSelectorColor =#675543
    机器人:textColorSecondary =#897530
    机器人:textColorPrimary =#359875
/&GT;


解决方案

基本模式

所有你所要做的就是设置你的口音的颜色在您的活动的主题是:

 &LT;项目名称=colorAccent&GT;#3333CC&LT; /项目&GT;

这将设置你所有的颜色,所以你不会弄乱造型。

这也意味着你不应该直接设置你的TimePicker像 amPmBackgroundColor 价值,让Android为你做的事情。的)

高级模式

如果要单独指定所有可能的值,请执行以下操作:

首先在活动的主题定义的:

 &LT;项目名称=机器人:timePickerStyle&GT; @风格/ Theme.MyTheme.TimePicker&LT; /项目&GT;

然后创建一个合适的样式:

 &LT;样式名称=Theme.MyTheme.TimePicker父=机器人:Widget.Material.Light.TimePicker&GT;
    &LT;项目名称=机器人:timePickerMode&GT;时钟&LT; /项目&GT;
    &LT;项目名称=机器人:headerBackground&GT;#ff555555&LT; /项目&GT;
    &LT;项目名称=机器人:numbersTextColor?&GT;机器人:ATTR / textColorPrimaryActivated&LT; /项目&GT;
    &LT;项目名称=机器人:numbersInnerTextColor?&GT;机器人:ATTR / textColorSecondaryActivated&LT; /项目&GT;
    &LT;项目名称=机器人:numbersSelectorColor?&GT;机器人:ATTR / colorControlActivated&LT; /项目&GT;
    &LT;项目名称=机器人:numbersBackgroundColor&GT;#ff555555&LT; /项目&GT;
    &LT;项目名称=机器人:amPmTextColor&GT;的android:ATTR / textColorSecondary&LT; /项目&GT;
&LT; /风格&GT;

注意 numbersInnerTextColor 只能从API级别23和其它样式(如 headerTextColor )不能设置(或至少我不能使它工作)。

我会建议不要使用高级模式作为TimePicker应该有颜色的含活性相同,这样做,否则可能会产生严重的影响您的UX。

I am unable to change the selector color and other parts of the TimePicker. So far, I can change header color and background but I am unable to change the innercircle and the textcolor.

Change custom theme link.

My code :

<TimePicker
    android:id="@+id/tp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:timePickerMode="clock"
    android:headerBackground="#565466"
    android:amPmBackgroundColor="#500126"
    android:numbersBackgroundColor="#57e326"
    android:numbersTextColor="#995394"
    android:numbersSelectorColor="#675543"
    android:textColorSecondary="#897530"
    android:textColorPrimary="#359875"
/>

解决方案

Basic mode

All you have to do is set your accent color in your Activity's theme:

<item name="colorAccent">#3333cc</item>

This will set all the colors for you so you wouldn't mess up the styling.

(This also means that you shouldn't set values like amPmBackgroundColor on your TimePicker directly, let Android do the things for you.)

Advanced mode

If you want to specify all the possible values separately, do the following:

First define this in your Activity's theme:

<item name="android:timePickerStyle">@style/Theme.MyTheme.TimePicker</item>

Then create the appropriate style:

<style name="Theme.MyTheme.TimePicker" parent="android:Widget.Material.Light.TimePicker">
    <item name="android:timePickerMode">clock</item>
    <item name="android:headerBackground">#ff555555</item>
    <item name="android:numbersTextColor">?android:attr/textColorPrimaryActivated</item>
    <item name="android:numbersInnerTextColor">?android:attr/textColorSecondaryActivated</item>
    <item name="android:numbersSelectorColor">?android:attr/colorControlActivated</item>
    <item name="android:numbersBackgroundColor">#ff555555</item>
    <item name="android:amPmTextColor">?android:attr/textColorSecondary</item>
</style>

Note that numbersInnerTextColor is only available from API level 23 and other styles (e.g. headerTextColor) can't be set (or at least I couldn't make it work).

I'd advise against using the "advanced" mode as the TimePicker should have the same colors as the containing Activity and doing otherwise might impact your UX in a bad way.

这篇关于如何自定义TimePicker在材料设计的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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