Xamarin Android - Change colors for TimePicker keyboard view

与世无争的帅哥 提交于 2021-01-01 06:10:21

问题


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".


回答1:


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



来源:https://stackoverflow.com/questions/62643871/xamarin-android-change-colors-for-timepicker-keyboard-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!