10

我正在尝试创建一个自定义对话框,基本上我正在使用DatePickerDialog.THEME_HOLO_DARK,但我想更改“分隔线”颜色和文本颜色。

在此处输入图像描述

我想将蓝线和文本颜色更改为红色。

提前致谢!

编辑:

使用此代码:

<style name="testo" parent="@android:style/Widget.DeviceDefault.DatePicker">
    <item name="android:divider">@drawable/dialog_divider</item>
</style>

这就是我得到的: 在此处输入图像描述

分隔线的drawable基本上是一条红线..

4

6 回答 6

1

您必须创建自己的主题来扩展 THEME_HOLO_DARK。更改android应用程序的基本主题颜色

编辑:尝试这样的事情

<style name="testo" parent="@android:style/Widget.DeviceDefault.DatePicker">
    <item name="android:divider">@drawable/MyDivider</item>
</style>

并将对主题的引用传递给构造函数

于 2012-10-03T15:07:32.270 回答
1

将此项目添加到您的主题中

<item name="numberPickerStyle">@style/MyApp.NumberPicker</item>

以这种风格设置自定义分隔线颜色

<style name="MyApp.NumberPicker" parent="Widget.Holo.NumberPicker">
   <item name="selectionDivider">@color/white</item>
</style>

编辑:仅在 HoloEverywhere 上测试

于 2013-06-29T11:46:59.443 回答
0

我知道这是一个迟到的回复,但我想与那些经历过或将来会遇到这个问题的人分享我的发现。

我搜索了很多地方,我找到的唯一解决方案是 SimonVT 的 Pickers。

实现该库后,更改颜色非常容易。在 numberpicker 中,该库使用可以简单地替换为所需设计的图像。

此示例具有三个选择器:NumberPicker、DatePicker 和 TimerPicker。

https://github.com/rodrigobusata/android-pickers

希望对你有帮助。


更新

上面的链接已经不存在了,现在你必须使用 Material Design https://github.com/wdullaer/MaterialDateTimePicker

于 2015-01-20T19:49:41.923 回答
0
     fun applyStyLing(timePickerDialog: DatePickerDialog,context: Context) {

        try {
            var dividerId = timePickerDialog.getContext().getResources().getIdentifier("titleDivider", "id", "android")
            val divider = timePickerDialog.findViewById<View>(dividerId)
            divider.setBackgroundColor(ContextCompat.getColor(context, R.color.colorDatePicker))

            var dividerId1 = timePickerDialog.getContext().getResources().getIdentifier("alertTitle", "id", "android")
            val divider1 = timePickerDialog.findViewById<TextView>(dividerId1)
            divider1.setTextColor(ContextCompat.getColor(context, R.color.colorDatePicker))

            val system = Resources.getSystem()
            val hourNumberPickerId = system.getIdentifier("day", "id", "android")
            val minuteNumberPickerId = system.getIdentifier("month", "id", "android")
            val ampmNumberPickerId = system.getIdentifier("year", "id", "android")

            val hourNumberPicker = timePickerDialog.findViewById<View>(hourNumberPickerId) as NumberPicker
            val minuteNumberPicker = timePickerDialog.findViewById<View>(minuteNumberPickerId) as NumberPicker
            val ampmNumberPicker = timePickerDialog.findViewById<View>(ampmNumberPickerId) as NumberPicker

            setNumberPickerDividerColour(hourNumberPicker,context)
            setNumberPickerDividerColour(minuteNumberPicker,context)
            setNumberPickerDividerColour(ampmNumberPicker,context)

        }catch (e:Exception)
        {
            e.printStackTrace()
        }

    }


private fun setNumberPickerDividerColour(number_picker: NumberPicker,context: Context) {
        val count = number_picker.childCount

        for (i in 0 until count) {

            try {
                val dividerField = number_picker.javaClass.getDeclaredField("mSelectionDivider")
                dividerField.isAccessible = true
                val colorDrawable = ColorDrawable(context.getResources().getColor(R.color.colorDatePicker))
                dividerField.set(number_picker, colorDrawable)

                number_picker.invalidate()
            } catch (e: NoSuchFieldException) {
                Log.w("setNumberPickerTxtClr", e)
            } catch (e: IllegalAccessException) {
                Log.w("setNumberPickerTxtClr", e)
            } catch (e: IllegalArgumentException) {
                Log.w("setNumberPickerTxtClr", e)
            }

        }
    }
于 2018-08-10T07:00:21.770 回答
0

请使用以下代码

这里,dialog 是 DatePickerDialog 的一个对象。

    int dividerId = dialog.getContext().getResources().getIdentifier
            ("android:id/titleDivider", null, null);
    View divider = dialog.findViewById(dividerId);
    divider.setBackgroundColor(getResources().getColor(R.color.red));

    int textViewId = dialog.getContext().getResources().getIdentifier
            ("android:id/alertTitle", null, null);
    TextView tv = (TextView) dialog.findViewById(textViewId);
    tv.setTextColor(getResources().getColor(R.color.red));
于 2016-02-08T06:13:52.723 回答
-2

you can change the text color by doing something like

<style name="testo" parent="@android:style/Widget.DeviceDefault.DatePicker">

<item name="android:textColor">#FF0000</item>

</style>

Did you ever figure out how to change the divider color? I'm trying to do the same thing and can't really find anything at the moment.

于 2012-11-02T23:38:53.040 回答