【问题标题】:Android Material DateRangePicker has a different layout than in the official websiteAndroid Material DateRangePicker 布局与官网不同
【发布时间】:2021-08-14 22:06:08
【问题描述】:

我正在实现一个 dateRangePicker,它工作得非常好,但它的外观与 the first reply of this StackOverflowthe official material.io website 中的外观不同。

这是我的实现:

MaterialDatePicker<Pair<Long, Long>> pickerRange = MaterialDatePicker.Builder.dateRangePicker()
                .setTheme(R.style.ChipStyle)
                .setCalendarConstraints(limitRange().build())
                .setTitleText(getString(R.string.choose_date_range))
                .setSelection(new Pair<>(initialMillis, finalMillis))
                .build();

        pickerRange.addOnPositiveButtonClickListener(selection -> { ... });
        pickerRange.show(getSupportFragmentManager(), pickerRange.toString());

这是我现在使用的风格:

<style name="ChipStyle" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorSecondary">@color/colorPrimary</item>
    </style>

我已经尝试按照 StackOverflow 和官方网站中建议的方式实现样式,但我唯一能改变的是颜色,布局仍然关闭并且不同,如下所示图片。

左边的那个是我的,你可以看到布局看起来不同,当天的圆圈向右移动。如何让它看起来像之前提到的StackOverflow和官方网站中显示的预览?

【问题讨论】:

    标签: android datepicker material-components-android


    【解决方案1】:

    我遇到的问题是“AppTheme”的样式有Theme.AppCompat.*作为父级。

    将其更改为以下对我有用:

    <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
            <item name="android:fontFamily">@font/raleway</item>
        </style>
    

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 2020-10-13
      • 1970-01-01
      • 2015-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多