in my application my created custom dialog dont have full height and i can not change and customize that.for example see this screen shot:
My code:
final Dialog contacts_dialog = new Dialog(ActivityGroup.this, R.style.theme_sms_receive_dialog); contacts_dialog.setContentView(R.layout.dialog_schedule_date_time); contacts_dialog.setCancelable(true); contacts_dialog.setCanceledOnTouchOutside(true); contacts_dialog.show();
layout:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layoutRoot" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@null" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shape_header_dialog_background" android:orientation="horizontal" android:padding="4dp" > <TextView android:id="@+id/TextView21" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginRight="5dp" android:layout_weight="2" android:gravity="center_vertical|right" android:text="@string/choose_schedule_time_date" android:textColor="#ffffff" android:textSize="14sp" android:textStyle="bold" /> <ImageView android:id="@+id/ImageView03" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginTop="0dp" android:background="@drawable/icon_scudule_time" /> </LinearLayout> </LinearLayout>
Style:
<style name="theme_sms_receive_dialog" parent="android:style/Theme.Dialog"> <item name="android:windowNoTitle">true</item> <item name="android:background">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="numberPickerStyle">@style/NPWidget.Holo.Light.NumberPicker</item> </style>
According to Android platform developer Dianne Hackborn in this discussion group post, Dialogs set their Window's top level layout width and height to WRAP_CONTENT . To make the Dialog bigger, you can set those parameters to MATCH_PARENT . Demo code: AlertDialog.
Builder dd = new AlertDialog. Builder(this); dd. setView(view); dd. setCancelable(false); final AlertDialog d = dd.
You just have to give android:theme="@android:style/Theme. Dialog" in the android manifest. xml for your activity and can write the whole layout as per your requirement. you can set the height and width of your custom dialog from the Android Resource XML.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With