I'm creating a DatePickerDialogFragment
where the user will select date of birth. I am wanting to make sure I can handle dates which are non-gregorian. I have not been able to change which type of calendar to use on my device. Does Android give the user the capability to switch the calendar type? If so what are the steps? I have had no success in the settings so far.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
About the graphical user interface of a picker dialog for a non-gregorian calendar, you have really to implement it yourself from the scratch. The following notes are about the general availability of other calendars.
Old status of Android before API-level 24
Well, here we see (again) a difference between Oracle and Android. If you look at the source of older Android code then you see only the gregorian calendar being instantiated:
This is in contrast to what Oracle-Java does where two alternative calendars are described on the base of
java.util.Calendar
(selectable by locale or unicode-ca-extension): ThaiBuddhist (correct after 1940 only) and JapaneseImperial (since Meji-era).Android-N (API-level 24)
However, starting with API-level 24 (Android-N), Google has introduced new calendars overtaken from ICU4J-project. These calendars can be found in the package android.icu.util:
Current status of Android (API-level 26 or higher)
The new
java.time
-API has been introduced, so following four non-gregorian calendars have been incorporated:Alternatives?
To be realistic, there are mainly three 3rd-party libraries which promise to offer alternative calendars also for older Android versions.
=> Threeten-ABP
This is a thin wrapper around the backport of new time library built into Java-8 which has introduced 4 partially new calendars: Islamic-Umalqura (Saudi-Arabia), Minguo (Taiwan), ThaiBuddhist (correct only after 1940) and Japanese (since Meji era only).
If Android developers accept the level 26+ then Threeten-ABP is obviously unnecessary. Otherwise...
The Japanese calendar has been fixed in version v1.0.5. But the islamic calendar is still a negative surprise because it is NOT the Umalqura-variant but rather comparable to Microsoft Kuwaiti variant and only allows an awkward configuration via a file (accessible on Android???). Another big problem of all calendars is the lack of any localization support, example:
The 7th islamic month is correctly called "Rajab", not "July" (and we are now in April at the time of writing this post!). And as said before, the islamic day can vary dependent on the variant of islamic calendar so the calculation is often wrong which makes the whole islamic calendar of this library unuseable.
=> Joda-Time-Android
This is a wrapper around Joda-Time. It officially offers 8 pluggable calendars. The term "pluggable" means, you can choose a "chronology" and configure an object of type
LocalDate
with this chronology.If you carefully study the offered calendars then you will see that the real non-iso-calendars (non-gregorian) are:
For completeness, there is also a bridge version (modelling a simple switch between gregorian and julian calendar rules).
But again, localization support is completely missing, see also this old issue. And since Joda-Time is officially in maintenance mode, we cannot reasonably expect any further development:
=> my library Time4A
This is the biggest library (Proguard can help to shrink it however). It offers following calendars:
All calendars offer wide i18n-support mostly based on CLDR-data.
Android does not seem to support any other calendars. In fact, the
Calendar
class only has one direct subclass:GregorianCalendar
.See the Android API reference for the Calendar class.
For supporting another calendar in the
DatePickerDialogFragment
you will have to implement it yourself.