将 DatePickerDialog 按钮更改为文本

Szu*_*ler 9 android android-datepicker kotlin

嗨,我想调整我的DatePickerDialog, 而不是底部的按钮(显示在下图中),我只想制作蓝色文本。

这是我如何创建 DatePickerDialog

private val birthdayDate by lazy {
    Calendar.getInstance()
}
private val datePicker by lazy {
    DatePickerDialog(
        context,
        R.style.MyDatePickerDialogTheme,
        this,
        birthdayDate.get(Calendar.YEAR),
        birthdayDate.get(Calendar.MONTH),
        birthdayDate.get(Calendar.DAY_OF_MONTH)
    ).also {
        it.datePicker.maxDate = Calendar.getInstance().timeInMillis
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我只是调用 show 方法来显示对话框。我认为问题出在我的某个地方style,但我找不到在哪里。任何帮助将不胜感激。

<style name="MyDatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">@color/colorPrimary</item>
</style>
Run Code Online (Sandbox Code Playgroud)

Szu*_*ler 19

所以我终于找到了解决方案。我MyDatePickerDialogThemeDatePicker. 解决方案看起来像这样:

<style name="MyDatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="android:buttonBarPositiveButtonStyle">@style/DatePickerButtonStyle</item>
    <item name="android:buttonBarNegativeButtonStyle">@style/DatePickerButtonStyle</item>
</style>

<style name="DatePickerButtonStyle" parent="Base.Widget.AppCompat.Button.Borderless">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:backgroundTint">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)


小智 0

如此链接中所列 ,您可以使用此主题

DatePickerDialog dpd = new DatePickerDialog(getActivity(),
                    AlertDialog.THEME_DEVICE_DEFAULT_LIGHT,this,year,month,day); 
Run Code Online (Sandbox Code Playgroud)

达到你想要的