Android get full width for custom Dialog
You need to get the current Window and set it's LayoutParams
like so:
Dialog d=new Dialog(mContext);..................myDialog.show();Window window = myDialog.getWindow();window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
Alternative(if above solution does't works)
In case above code not works well you can use a workaround
styles.xml
<style name="mydialog"></style>
Java
Dialog d=new Dialog(mContext,R.style.mydialog);..................myDialog.show();Window window = myDialog.getWindow();window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
Two ways this can be done, first one in style.xml and second in code:
- Add as below in style.xml, alter the value(currently 90%) to meet your needs.
<style name="Theme_Dialog" parent="android:Theme.Holo.Dialog"> <item name="android:windowMinWidthMajor">90%</item> <item name="android:windowMinWidthMinor">90%</item></style>
- Add setlayout to match_parent
final Dialog contacts_dialog = new Dialog(ActivityGroup.this, R.style.theme_sms_receive_dialog); contacts_dialog.setContentView(R.layout.dialog_schedule_date_time);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT); contacts_dialog.setCancelable(true); contacts_dialog.setCanceledOnTouchOutside(true); contacts_dialog.show();
For full width dialog you can create custom style for dialog. Code is given below for full width dialog:
<style name="Custom_Dialog" parent="ThemeOverlay.AppCompat.Light" > <item name="windowMinWidthMajor">100%</item> <item name="windowMinWidthMinor">65%</item></style>
To assign this style to the dialog's constructor, add this to onCreate()
method right after setContentView()
:
getWindow() .setLayout( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT );