android - DatePicker Widget does not take up entire AlertDialog on Nexus 6 -
i have datepickerfragment uses simple custom layout. layout takes entire alert dialog on smaller devices (htc 1 m7), not on nexus 6. know why datepicker not take entire width of nexus 6 alert dialog or begin troubleshooting? thank you!
nexus 6 (notice date header not fill entire alert dialog)
htc 1 m7
dialog_date.xml
<?xml version="1.0" encoding="utf-8"?> <datepicker xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialog_date_date_picker" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:calendarviewshown="false"> </datepicker>
oncreatedialog() of datepickerfragment
public dialog oncreatedialog(bundle savedinstancestate) { date date = (date) getarguments().getserializable(arg_date); calendar calendar = calendar.getinstance(); calendar.settime(date); int year = calendar.get(calendar.year); int month = calendar.get(calendar.month); int day = calendar.get(calendar.day_of_month); view v = layoutinflater.from(getactivity()) .inflate(r.layout.dialog_date, null); mdatepicker = (datepicker) v.findviewbyid(r.id.dialog_date_date_picker); mdatepicker.init(year, month, day, null); return new alertdialog.builder(getactivity()) .setview(v) // .settitle(r.string.date_picker_title) .setpositivebutton(android.r.string.ok, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { int year = mdatepicker.getyear(); int month = mdatepicker.getmonth(); int day = mdatepicker.getdayofmonth(); date date = new gregoriancalendar(year, month, day).gettime(); sendresult(activity.result_ok, date); } }) .create(); }
alert dialog has strict (weird?) rules governing it's size. i'm not sure how solve it, there's workaround - once dialog shown can force it's width match date-picker's width. solved me, it'll work too:
public dialog oncreatedialog(bundle savedinstancestate) { ... final alertdialog alertdialog = new alertdialog.builder(getactivity()) ... .create(); alertdialog.setonshowlistener(new dialoginterface.onshowlistener() { @override public void onshow(dialoginterface dialog) { windowmanager.layoutparams lp = new windowmanager.layoutparams(); final window window = getdialog().getwindow(); lp.copyfrom(window.getattributes()); final view picker = window.findviewbyid(r.id.dialog_date_date_picker); lp.width = picker.getwidth(); lp.height = picker.getheight(); window.setattributes(lp); } }); return alertdialog; }
Comments
Post a Comment