在android中更改TimePicker字体颜色

时间:2014-01-10 13:39:43

标签: android android-timepicker

我需要将TimePicker字体颜色设置为白色。我尝试了this问题中描述的方法,但它对我不起作用。所以任何想法我怎么能这样做?

2 个答案:

答案 0 :(得分:0)

您可以添加如下样式:

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

并将其添加到您的代码中:

    TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(),R.style.TimePickerTheme, (TimePickerDialog.OnTimeSetListener) getActivity(), hour, minute, android.text.format.DateFormat.is24HourFormat(getActivity()));

答案 1 :(得分:0)

创建样式:

 <style name="MyBase.TimePicker" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:background">@android:color/black</item>
        <item name="android:headerBackground">@android:color/black</item>
        <item name="android:textColor">@android:color/white</item>
        <item name="android:colorAccent">@android:color/white</item>
        <item name="android:textColorPrimary">@android:color/white</item>
    </style>

然后像这样在您的TimePicker中使用它:

<TimePicker xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/tpScheduleTime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:theme="@style/MyBase.TimePicker"
            android:timePickerMode="spinner" />