【问题标题】:Can't customize TimePicker colors无法自定义 TimePicker 颜色
【发布时间】:2018-05-29 10:14:47
【问题描述】:

我试图让我的时间选择器看起来像这样: The desired outcome

所以我正在做我在This guide上找到的东西

这就是我实际得到的:The true outcome

这是我的自定义样式:

<style name="customTimePicker" parent="@android:style/Widget.Material.TimePicker">
    <item name="android:timePickerMode">clock</item>
    <item name="android:headerBackground">#0076a3</item>
    <item name="android:numbersTextColor">#ffffff</item>
    <item name="android:numbersInnerTextColor">#ffffff</item>
    <item name="android:numbersSelectorColor">#fbc014</item>
    <item name="android:numbersBackgroundColor">#004a80</item>
    <item name="android:amPmTextColor">#ffffff</item>
</style>

这就是我在我的 XML 文件中使用它的方式:

<TimePicker
    android:id="@+id/tpAnalog"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:theme="@style/customTimePicker"
    style="@style/customTimePicker"
    android:visibility="visible"/>

在 android studio 的预览屏幕上,看起来就像我想要的 preview on Android studio

那么为什么当我在我的设备上运行它时它不起作用?

编辑:我忘了在我的活动主题上使用这行代码:

<item name="android:timePickerStyle">@style/customTimePicker</item>

这似乎解决了我所有的问题,只是我仍然无法更改所选数字的文本颜色。 This is the text I want to change。这可能吗?

【问题讨论】:

    标签: android android-view android-custom-view android-timepicker


    【解决方案1】:

    <style name="MyAppTheme" parent="Theme.AppCompat.Light">
    <item name="colorAccent">#ff6d00</item>
    <item name="colorControlActivated">#33691e</item>
    <item name="android:selectableItemBackgroundBorderless">@color/colorPrimaryDark</item>
    <item name="colorControlHighlight">#d50000</item>
    

    【讨论】:

      【解决方案2】:

      使用这种样式对我来说改变背景颜色很有用。

        <style name="MyTimePickerWidgetStyle" parent="@android:style/Widget.Material.TimePicker">
                  <item name="android:headerBackground">#0076A3</item>
                  <item name="android:numbersTextColor">#b71c1c</item>
                  <item name="android:numbersInnerTextColor">#f44336</item>
                  <item name="android:numbersSelectorColor">#DCA811</item>
                  <item name="android:numbersBackgroundColor">#004A80</item>
                  <item name="android:amPmTextColor">#fff</item>
              </style>
              <TimePicker
              android:id="@+id/timePicker"
              android:layout_height="match_parent"
              android:layout_width="match_parent"
              android:background="#359EF3"
              android:theme="@style/MyTimePickerWidgetStyle"
              style="@style/MyTimePickerWidgetStyle" />
      

      【讨论】:

        猜你喜欢
        • 2019-06-01
        • 2019-02-25
        • 1970-01-01
        • 2020-08-04
        • 2021-01-11
        • 2021-06-24
        • 2015-06-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多