Xamarin Android-更改TimePicker键盘视图的颜色 [英] Xamarin Android - Change colors for TimePicker keyboard view

查看:79
本文介绍了Xamarin Android-更改TimePicker键盘视图的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够更改时钟视图的颜色设置(这很有帮助

但是在第二个视图中我并不那么成功(按第一个图像左下方的键盘图标).如何更改SubTitle,InputField和说明的颜色(看起来像纯黑色的图像中心)?有人知道吗?

有没有我忽略的文档?拥有一个包含所有键(例如"android:numbersTextColor")的列表会很棒.第二个视图的颜色托盘等.

感谢您的辛勤工作.谢谢:-)

修改

"Leon Lu-MSFT";感谢您的回答.这使得可以在键盘"下为视图设置样式.是否有可能为输入字段上方和下方的文本设置不同的颜色,即"AM"/"PM"?文字和取消"/确定"?

不幸的是,在应用提供的样式后,时钟视图变成了这种视图.

完整的Android风格

 < style name =" MainTheme"parent ="MainTheme.Base"</style><!-无论使用什么API,基本主题都适用-><样式名称="MainTheme.Base";parent ="Theme.AppCompat.Light.DarkActionBar".<!-如果您使用的是22.1版,请仅使用windowNoTitle.没有android:->< item name ="windowNoTitle"> true</item><!-我们将使用工具栏,因此无需显示ActionBar->< item name ="windowActionBar"> false</item>< ;!-通过https://aka.ms/material-colors->设置主题颜色.<!-colorPrimary用于默认操作栏背景-><项目名称="colorPrimary">#2196F3</项目><!-colorPrimaryDark用于状态栏-><项目名称="colorPrimaryDark">#1976D2</项目><!-colorAccent用作colorControlActivated的默认值用于着色小部件-><项目名称="colorAccent">#f59b00</项目><!-您还可以设置colorControlNormal,colorControlActivatedcolorControlHighlight和colorSwitchThumbNormal.->< item name ="windowActionModeOverlay"> true</item>< item name =" android:datePickerDialogTheme" @ style/AppCompatDialogStyle</item>< item name =" android:timePickerDialogTheme" @ style/TimePickerLightTheme</item>< item name =" android:timePickerStyle> @ style/TimePickerLightStyle</item>< item name ="android:textAllCaps"> false</item></style>< style name =" AppCompatDialogStyle"parent ="Theme.AppCompat.Light.Dialog".<项目名称="colorAccent">#f59b00</项目></style><样式名称="TimePickerLightTheme";parent ="Theme.AppCompat.Light.Dialog".< item name ="android:background">#4b4b4b</item>< item name ="android:colorAccent">#2c2f30</item>< item name =" android:textColor>#f59b00</item>< item name =" android:textColorPrimary">#ffffff</item></style>< style name ="TimePickerLightStyle"parent ="android:Widget.Material.Light.TimePicker"< item name =" android:headerBackground>#2c2f30</item>< item name =" android:numbersTextColor>#ffffff</item>< item name =" android:numbersInnerTextColor">#ffffff</item>< item name =" android:numbersSelectorColor>#f59b00</item>< item name =" android:numbersBackgroundColor>#4b4b4b</item>< item name ="android:background">#1f1f1f</item>< item name =" android:textColorPrimary>#a1a1a1</item></style> 

是否有一个包含所有我要忽略的元素的键的列表?拥有一个清单,上面写着键X用于视图元素Y的颜色"之类的列表,将是很棒的.

解决方案

是否要更改SubTitle,InputField和描述的颜色,如以下屏幕截图所示?

创建 Theme.picker 样式.

 < style name =" Theme.picker"parent ="Theme.AppCompat.Light.Dialog".//背景颜色< item name ="android:background">#FFC107</item>//标题背景颜色<项目名称="colorAccent">#FF0000</项目>//文字颜色< item name =" android:textColor"> @android:color/white</item>//edittext颜色< item name =" android:textColorPrimary"> @android:color/holo_green_light</item></style> 

它们在时间选择器中使用.

 < TimePickerandroid:layout_width =" match_parent"android:layout_height =" wrap_content"android:theme ="@ style/Theme.picker"/> 

如果您使用的是xamarin形式.则应以< style name =" MainTheme.Base"parent =" Theme.AppCompat.Light.DarkActionBar">

 < item name =" android:timePickerDialogTheme> @ style/Theme.picker</item> 

=====更新======

有可能为输入字段上方和下方的文本设置不同的颜色,即"AM"/"PM".文字和取消"/确定"?

如果要设置它,只需在< item name =" android:textColor" @android:color/red</item> 标签中更改颜色即可.第一视图和第二视图的文本颜色将被更改,它将同时设置两者.如果要为不同的视图设置不同的项目,则应制作一个自定义的 TimePicker

I was able to change the color setting for the clock view (That was helpful https://www.tutorialsbuzz.com/2019/09/android-timepicker-dialog-styling.html)

But I wasn't so successful at the second view (press the keyboard icon at the bottom left of the first image). How to change the color of SubTitle, InputField and description (center of the image that looks pure black)? Has anyone an idea?

Is there a documentation that I overlook? Would be great to have a list with all keys like "android:numbersTextColor" etc. for the color pallet of the second view.

I appreciate your time and effort. Thanks :-)

Edit

"Leon Lu - MSFT" thanks for your answer. That made it possible to style the view under "Keyboard". Is it possible to set different colors for the text above and below the input field, the "AM"/"PM" text and "cancel"/"ok"?

Unfortunately the clock view changed into this after applying the provided style.

Complete Android Style

<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
    <item name="windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <!-- Set theme colors from https://aka.ms/material-colors -->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#2196F3</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#1976D2</item>
    <!-- colorAccent is used as the default value for colorControlActivated
     which is used to tint widgets -->
    <item name="colorAccent">#f59b00</item>
    <!-- You can also set colorControlNormal, colorControlActivated
     colorControlHighlight and colorSwitchThumbNormal. -->
    <item name="windowActionModeOverlay">true</item>
    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
    <item name="android:timePickerDialogTheme">@style/TimePickerLightTheme</item>
    <item name="android:timePickerStyle">@style/TimePickerLightStyle</item>
    <item name="android:textAllCaps">false</item>
</style>

<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#f59b00</item>
</style>

<style name="TimePickerLightTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:background">#4b4b4b</item>
    <item name="android:colorAccent">#2c2f30</item>
    <item name="android:textColor">#f59b00</item>
    <item name="android:textColorPrimary">#ffffff</item>
</style>

<style name="TimePickerLightStyle" parent="android:Widget.Material.Light.TimePicker">
    <item name="android:headerBackground">#2c2f30</item>
    <item name="android:numbersTextColor">#ffffff</item>
    <item name="android:numbersInnerTextColor">#ffffff</item>
    <item name="android:numbersSelectorColor">#f59b00</item>
    <item name="android:numbersBackgroundColor">#4b4b4b</item>
    <item name="android:background">#1f1f1f</item>
    <item name="android:textColorPrimary">#a1a1a1</item>
</style>

Is there a list with keys for all elements that I'm overlooking? Would be great to have a list where it says something like "Key X is for color of view element Y".

解决方案

Do you want to change the color of SubTitle, InputField and description like following screenshot?

Create the Theme.picker style.

 <style name="Theme.picker" parent="Theme.AppCompat.Light.Dialog">
    //background color
    <item name="android:background">#FFC107</item>
    //Title background color
    <item name="colorAccent">#FF0000</item>
    //text color
    <item name="android:textColor">@android:color/white</item>
    //edittext color
    <item name="android:textColorPrimary">@android:color/holo_green_light</item>
  </style>

Them use it in the Timepicker.

<TimePicker
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:theme="@style/Theme.picker"/>

If you used xamarin forms.You should add an item in <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">

   <item name="android:timePickerDialogTheme">@style/Theme.picker</item>

=====update======

Is it possible to set different colors for the text above and below the input field, the "AM"/"PM" text and "cancel"/"ok"?

If you want to set it, just change the color in the <item name="android:textColor">@android:color/red</item> tab. The textcolor of firstview and second view will be changed, it set both of them at the same time. If you want to set the diferent items for differen view, you should make a custom TimePicker

这篇关于Xamarin Android-更改TimePicker键盘视图的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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