如何更改 Android 中 DatePicker 和 TimePicker 对话框的默认颜色?

2024-01-16

有没有办法改变默认颜色DatePicker and TimePicker dialog?

这是我尝试过的代码

<DatePicker
                    style="@style/date_picker"
                    android:background="#6495ED"
                    android:id="@+id/DatePicker"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="5dip"
                    android:layout_marginRight="5dip" />

<TimePicker
                    android:id="@+id/TimePicker"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="5dip"
                    android:layout_marginRight="5dip" />

下面两行仅更改背景颜色,我想更改日期和时间选择器的默认银色。
请提供任何帮助。

style="@style/date_picker"
android:background="#6495ED"

更改选择器对话框的最佳方法是向其中添加自定义样式。

<style name="TimePickerTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">@color/color_primary</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
</style>

TimePickerDialog timePicker = new TimePickerDialog(mContext, R.style.TimePickerTheme, fromListener, hour, min, false);

非常适合我。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何更改 Android 中 DatePicker 和 TimePicker 对话框的默认颜色? 的相关文章

随机推荐