Android MaterialTimePicker 自定义样式

问题描述 投票:0回答:1

我正在尝试将自定义样式应用于 MaterialTimePicker。而且我仍然无法更改一些所需的颜色:

  1. 更改所选芯片背景颜色
  2. 更改所选芯片文本颜色
  3. 去除(或设置颜色)芯片标签

这是我的代码:

val timePicker =
MaterialTimePicker.Builder()
.setTitleText("Select time")
.setTheme(R.style.TimePicker)
.setInputMode(MaterialTimePicker.INPUT_MODE_KEYBOARD)
.build()

<style name="TimePicker" parent="ThemeOverlay.MaterialComponents.TimePicker">
        <item name="colorPrimary">@color/primary_71</item>
        <item name="colorSurface">@color/blue_22</item>
        <item name="colorOnSurface">@color/grey_100</item>
        <item name="materialButtonOutlinedStyle">@style/TimePicker.Button</item>
        <item name="chipStyle">@style/TimePicker.Chip</item>
        <item name="imageButtonStyle">@style/TimePicker.ImageButton</item>
        <item name="borderlessButtonStyle">@style/borderlessButtonStyle</item>
    </style>

    <style name="borderlessButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
        <item name="android:textColor">@color/picker_dialog_color_selector</item>
    </style>

    <style name="TimePicker.Button" parent="Widget.MaterialComponents.TimePicker.Button">
        <item name="backgroundTint">@color/time_picker_button_background_selector</item>
        <item name="android:layout_height">48dp</item>
        <item name="android:padding">0dp</item>
        <item name="android:insetTop">0dp</item>
        <item name="android:insetBottom">0dp</item>
        <item name="android:textColor">@color/time_picker_button_text_selector</item>
        <item name="android:textAlignment">center</item>
        <item name="strokeColor">@color/blue_37</item>
        <item name="strokeWidth">1dp</item>
    </style>

    <style name="TimePicker.Chip" parent="Widget.MaterialComponents.TimePicker.Display">
        <item name="chipBackgroundColor">@color/time_picker_chip_background_selector</item>
        <item name="rippleColor">@color/yellow_56</item>
        <item name="android:textAlignment">center</item>
        <item name="android:textColor">@color/time_picker_chip_text_selector</item>
    </style>

    <style name="TimePicker.ImageButton" parent="Widget.MaterialComponents.TimePicker.ImageButton">
        <item name="android:visibility">gone</item>
    </style>
android material-design android-theme
1个回答
0
投票

可以通过以下设置来完成:

<style name="TimePicker" parent="ThemeOverlay.MaterialComponents.TimePicker">
        <item name="colorPrimary">#7585A0</item>
        <item name="colorSurface">@color/blue_22</item>
        <item name="colorOnSurface">@color/grey_100</item>
        <item name="materialButtonOutlinedStyle">@style/TimePicker.Button</item>
        <item name="chipStyle">@style/TimePicker.Chip</item>
        <item name="imageButtonStyle">@style/TimePicker.ImageButton</item>
        <item name="borderlessButtonStyle">@style/borderlessButtonStyle</item>
        <item name="textInputStyle">@style/timePickerTextInputStyle</item>
    </style>

    <style name="timePickerTextInputStyle" parent="Widget.MaterialComponents.TimePicker.Display.TextInputLayout">
        <item name="materialThemeOverlay">@style/timePickerMaterialThemeOverlay</item>
    </style>

    <style name="timePickerMaterialThemeOverlay" parent="ThemeOverlay.MaterialComponents.TimePicker.Display.TextInputEditText">
        <item name="editTextStyle">@style/timePickerTextInputEditText</item>
        <item name="android:textViewStyle">@style/timePickerTextViewStyle</item>
    </style>

    <style name="timePickerTextInputEditText" parent="Widget.MaterialComponents.TimePicker.Display.TextInputEditText">
        <item name="android:textColor">@color/grey_100</item>
    </style>

    <style name="timePickerTextViewStyle" parent="Widget.MaterialComponents.TimePicker.Display.HelperText">
        <item name="android:visibility">gone</item>
    </style>
© www.soinside.com 2019 - 2024. All rights reserved.