Last active
March 10, 2021 08:11
-
-
Save alexanza/c680e95fbe8bf3f45608 to your computer and use it in GitHub Desktop.
Expiration date picker for credit card (tested on api 19 and up)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExpirationDatePickerDialog extends DatePickerDialog implements DatePicker.OnDateChangedListener { | |
public ExpirationDatePickerDialog(Context context, OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth) { | |
super( | |
context, | |
Build.VERSION.SDK_INT >= 21 ? R.style.MyDialogTheme : 0, | |
callBack, | |
year, | |
monthOfYear, | |
dayOfMonth | |
); | |
init(context); | |
} | |
private void init(Context context) { | |
setTitle(""); | |
getDatePicker().setMinDate(System.currentTimeMillis() - 1000); | |
getDatePicker().setCalendarViewShown(false); | |
int day = context.getResources().getIdentifier("android:id/day", null, null); | |
if(day != 0){ | |
View dayPicker = getDatePicker().findViewById(day); | |
if(dayPicker != null){ | |
dayPicker.setVisibility(View.GONE); | |
} | |
} | |
} | |
public void onDateChanged(DatePicker view, int year, int month, int day) { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<style name="MyDialogTheme" parent="android:Theme.Material.Light.Dialog"> | |
<item name="android:datePickerStyle">@style/MyDatePicker</item> | |
</style> | |
<style name="MyDatePicker" parent="android:Widget.Material.Light.DatePicker"> | |
<item name="android:datePickerMode">spinner</item> | |
</style> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment