Change Datepicker Calendar Size In Android Programmatically
I'm doing an Android application and I have to show a DatePickerDialog. The fact is that the application will be on a device with a smart screen and the calendar doesn't fit in it.
Solution 1:
you can change width
and height
DatePickerDialog programmatically, you just use WindowManager.LayoutParams params = dateForm.getWindow().getAttributes();
see this example:
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dateForm = new DatePickerDialog(this, R.style.AppTheme, new DatePickerDialog.OnDateSetListener() {
@Override
publicvoidonDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
}
}, year, month, day);
DatePicker dp = dateForm.getDatePicker();
WindowManager.LayoutParams params = dateForm.getWindow().getAttributes();
params.gravity = Gravity.TOP;
// params.x = 0; // locationByX;// params.y = 0; // locationByY;params.width = 600; // dialogWidth;// params.height = 1000; // dialogHeight;
dateForm.getWindow().setAttributes(params);
dateForm.show();
// dp.setScaleY(Float.parseFloat("0.7"));// dp.setScaleX(Float.parseFloat("0.7"));
Solution 2:
Try this
dateForm.getWindow().setLayout(width,height)
width & height specific as device resolution size maintain dimension file or use SDP Library for that.
or for that specific resolution use AlertDialog.THEME_HOLO_LIGHT as below :
DatePickerDialogdateForm=newDatePickerDialog(ViewForm.this, AlertDialog.THEME_HOLO_LIGHT, newDatePickerDialog.OnDateSetListener() {}
Solution 3:
Following code can be used:
if(datePickerDialog.getWindow()!=null) {
datePickerDialog.getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT);datePickerDialog.getWindow().setGravity(Gravity.CENTER);
}
Instead of LayoutParams.WRAP_CONTENT, You can set custom width and height as well.
Post a Comment for "Change Datepicker Calendar Size In Android Programmatically"