如何更改Android微调器DatePicker文本外观?

izkcnapc  于 2023-05-27  发布在  Android
关注(0)|答案(1)|浏览(101)

这是我的DatePicker的风格:

<style name="AppDatePicker">
    <item name="android:textAppearance">?textAppearanceLabelSmall</item> <!-- This effects nothing. -->
    <item name="android:colorControlNormal">?colorPrimary</item>
</style>

我的Datepicker:

<DatePicker
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:calendarViewShown="false"
    android:datePickerMode="spinner"
    android:spinnersShown="true"
    android:theme="@style/AppDatePicker" />

如何更改微调器DatePicker的文本外观?

4ktjp1zp

4ktjp1zp1#

在此处遵循xml attrs:https://developer.android.com/reference/android/widget/DatePicker#summary
我们有:

android:dayOfWeekTextAppearance
android:headerMonthTextAppearance
... and more

sdk28不推荐使用这些attr
其他解决方案,为日期选择器创建主题并设置CalendarStyle

<style name="MyDatePicker" parent="....">
        <item name="android:calendarViewStyle">@style/MyCalendar</item>

<!-- For spinner -->
<item name="android:textColorPrimary">@color/...</item>
<item name="fontFamily">...</item>
<item name="android:textSize">...</item>

</style>

<style name="MyCalendar" parent="...">
   <item name="android:dateTextAppearance">Your text appearance</item>
</style>

使用它

<DatePicker
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/MyDatePicker" .../>

相关问题