项目作者: gantonious

项目描述 :
An elegant day of the week picker inspired by Google's clock app
高级语言: Kotlin
项目地址: git://github.com/gantonious/MaterialDayPicker.git
创建时间: 2017-11-04T19:25:36Z
项目社区:https://github.com/gantonious/MaterialDayPicker

开源协议:MIT License

下载


MaterialDayPicker

CircleCI Download

Inspired by the day picker in the builtin Android clock app.

Note: I’m not actively working on new features for this library. I’m only addressing critical bugs. With that being said contributions for new features are more than welcome and I am available to review pull requests. See contributing.md if you’re interested in contributing.

Normal Usage Localized Usage Dark Mode Usage
Default Usage Localized Usage Dark Mode Usage

Features

  • 🎨 Customizable theming
  • ✅ Easy to use API/hooks
  • 🌎 Fully localized
  • 👻 Supports dark mode

What’s New: Version 0.7.4 - Better Configuration + Bug fixes

  • You can now manually override the first day of the week shown in the picker by using the newly added firstDayOfWeek property

Changes from 0.7.3

  • Upgraded MaterialDayPicker to target API 30 and upgraded its AndroidX dependencies

Changes from 0.7.2

Bug fixes

  • Fixes a bug when using android gradle plugin 3.6.1 that would cause building to fail due to not being able to find the selectionMode attribute.

Changes from 0.7.1

Bug fixes

  • Fixes an issue where calling setSelectedDays would cause selected days to flash off and on.

Changes from 0.7.0

Configuration Improvements

  • You can now enable/disable days from being selected using enableDay/disableDay methods. See more below.
  • You can now set the selection mode via xml by using the app:selectionMode attribute.

Download the latest version by adding the following to your project’s build.gradle file:

  1. dependencies {
  2. implementation 'ca.antonious:materialdaypicker:0.7.4'
  3. }

Using MaterialDayPicker in your App

You can just drop the view into your existing xml:

  1. <ca.antonious.materialdaypicker.MaterialDayPicker
  2. android:id="@+id/day_picker"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"></ca.antonious.materialdaypicker.MaterialDayPicker>

You can get the currently selected days by using:

  1. val selectedDays = materialDayPicker.selectedDays
  2. // returns [MaterialDayPicker.Weekday.TUESDAY, MaterialDayPicker.Weekday.FRIDAY]

You can set the selected days by doing:

  1. val daysToSelect = listOf(MaterialDayPicker.Weekday.TUESDAY, MaterialDayPicker.Weekday.FRIDAY)
  2. materialDayPicker.setSelectedDays(daysToSelect)

If you want to only allow one day to be selected at a time you can do:

  1. materialDayPicker.selectionMode = SingleSelectionMode.create()

This can also be set via xml using the selectionMode attribute:

  1. <ca.antonious.materialdaypicker.MaterialDayPicker
  2. ...
  3. app:selectionMode="ca.antonious.materialdaypicker.SingleSelectionMode"></ca.antonious.materialdaypicker.MaterialDayPicker>

You can enable/disable days using the following methods. Note if you disable a day when it’s selected it cannot be deselected:

  1. materialDayPicker.enableDay(MaterialDayPicker.Weekday.Monday)
  2. materialDayPicker.disableDay(MaterialDayPicker.Weekday.Monday)
  3. materialDayPicker.setDayEnable(MaterialDayPicker.Weekday.Monday, isEnabled = false)

If you want to listen to whenever the day selection is changed you can use:

  1. materialDayPicker.setDaySelectionChangedListener { selectedDays ->
  2. // handle selection change
  3. }

If you need to know when a specific day is selected/deselected you can use:

  1. materialDayPicker.setDayPressedListener { weekday, isSelected ->
  2. // handle weekday selection
  3. }

Customizing MaterialDayPicker for your App

You can override these colors to change how MaterialDayPicker looks. You can also update these values in your night color resources directory to update how MaterialDayPicker looks in dark mode:

  1. <color name="dayPressed">@color/colorPrimaryDark</color>
  2. <color name="daySelected">@color/colorPrimary</color>
  3. <color name="daySelectedTextColor">@android:color/white</color>
  4. <color name="dayDeselected">#FAFAFA</color>
  5. <color name="dayDeselectedTextColor">@android:color/black</color>
  6. <!-- Customizing colors for disabled days-->
  7. <color name="daySelectedAndDisabled">#43444F</color>
  8. <color name="daySelectedAndDisabledTextColor">@color/daySelectedTextColor</color>
  9. <color name="dayDeselectedAndDisabled">@color/dayDeselected</color>
  10. <color name="dayDeselectedAndDisabledTextColor">@android:color/darker_gray</color>

If you don’t want to use the device’s current locale you can override it by doing:

  1. materialDayPicker.locale = Locale.ENGLISH // or any other locale

If you want to specify the first day of the week explicitly:

  1. materialDayPicker.firstDayOfWeek = MaterialDayPicker.Weekday.MONDAY // or any other day

License

  1. MIT License
  2. Copyright (c) 2017 George Antonious
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.