Reputation: 1813
My designers would like to show a DatePicker
which looks like a dropdown-list:
Is it a good idea to use Spinner
to implement the same? Would I have to write my own logic to take care of how many days fall in which months, leap years etc.?
Or is there any way to customise the Android DatePicker
or any other widget to achieve this functionality wherein I don't have to take care of writing logic for handling the dates?
Is the practice recommended at all?
Upvotes: 2
Views: 7006
Reputation: 176
You can set style in Programmer.
etDOB.setOnClickListener(v -> {
DatePickerDialog dialog = new DatePickerDialog(this, android.R.style.Theme_Holo_Dialog, date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH));
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.show();
});
Upvotes: 0
Reputation: 1554
Take a look at this library: https://github.com/code-troopers/android-betterpickers.
Gradle:
compile 'com.code-troopers.betterpickers:library:3.1.0'
In your Activity;
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DatePickerBuilder dpb = new DatePickerBuilder()
.setFragmentManager(getSupportFragmentManager())
.setStyleResId(R.style.BetterPickersDialogFragment)
.setYearOptional(true);
dpb.show();
}
});
Otherwise: many more opensource libraries; https://android-arsenal.com/tag/27?sort=rating
Upvotes: 1
Reputation: 5229
If you want the spinner-style date picker, you can set the datePickerMode attribute of DatePicker to spinner.
<DatePicker
...
android:datePickerMode="spinner" />
Upvotes: 1