Android get full width for custom Dialog
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>
add a comment |
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>
add a comment |
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>
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>
edited Feb 14 '15 at 20:12
DolDurma
asked Feb 14 '15 at 7:48
DolDurmaDolDurma
3,4021265136
3,4021265136
add a comment |
add a comment |
9 Answers
9
active
oldest
votes
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();
Oh i'm sorry sir. i'm update post title toAndroid get full width for custom Dialog
– DolDurma
Feb 14 '15 at 20:13
2
Just use the above code and make the width as 100%<item name="android:windowMinWidthMinor">100%</item>
– Psypher
Feb 14 '15 at 20:15
1
Thanks sir. i get this error now:windowMinWidthMinor requires API level 11 (current min is 8)
– DolDurma
Feb 15 '15 at 5:22
Perfectly what I was looking for!! THANKS
– Manza
Jan 9 '16 at 19:47
great its working for me as charm
– satvinder singh
Sep 16 '17 at 8:48
add a comment |
You need to get the current Window and set it's LayoutParams like so:
Dialog d=new Dialog(mContext,R.style.mydialog);
.........
.........
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);
that helped me , thanks
– mohnage7
Apr 11 '17 at 13:03
@MohNage7enjoy :)
– Abhishek Singh
Apr 12 '17 at 4:39
perfect answer!
– Amrutha Saj
Sep 14 '17 at 13:06
I never thoutht LayoutParams.MATCH_PARENT and LayoutParams.WRAP_CONTENT before. Thanks...
– Yusuf Çağlar
May 8 '18 at 16:13
1
The key here is to set it after calling show();. If you add it before this will not work. That was the issue with me. Thanks
– Vivek Mishra
Aug 25 '18 at 16:28
|
show 1 more comment
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
);
2
Add setLayout() after setContentView() saved me! Thanks
– AvatarQing
Jan 30 '18 at 8:17
add a comment |
In my case width of custom dialog shrinks in size(width) as the content inside dialog becomes smaller in width even though the the width property was set
android:layout_width="match_parent"
I just fixed that width to screen size and now its working according to my requirement
android:layout_width="320dp"
fixed my problem
– Ranjith Kumar
Apr 25 '17 at 13:24
add a comment |
In case anyone is wondering how to do it for a dialog shown using DialogFragment, you can override onCreateDialog to return a Dialog with custom style that has windowMinWidthMajor and minor set to 90%
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
return new Dialog(getActivity(), R.style.WideDialog);
Style:
<style name="WideDialog" parent="Base.Theme.AppCompat.Dialog">
<item name="android:windowMinWidthMajor">90%</item>
<item name="android:windowMinWidthMinor">90%</item>
</style>
add a comment |
Add code when you want to open dialog
final Dialog mBottomSheetDialog = new Dialog(getActivity(), R.style.MaterialDialogSheet);
mBottomSheetDialog.setContentView(R.layout.dialog_mainscreen_filter); // your custom view.
mBottomSheetDialog.setCancelable(true);
mBottomSheetDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
mBottomSheetDialog.getWindow().setGravity(Gravity.BOTTOM);
mBottomSheetDialog.show();
ImageView img_cross = mBottomSheetDialog.findViewById(R.id.img_cross);
final ImageView img_new = mBottomSheetDialog.findViewById(R.id.img_new);
final ImageView img_Used = mBottomSheetDialog.findViewById(R.id.img_Used);
img_cross.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
mBottomSheetDialog.dismiss();
);
img_new.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
img_new.setImageResource(R.drawable.checkbox_tick);
img_Used.setImageResource(R.drawable.checkbox_tick_gray);
);
img_Used.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
img_Used.setImageResource(R.drawable.checkbox_tick);
img_new.setImageResource(R.drawable.checkbox_tick_gray);
);
dialog's xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/colorWhite"
app:cardCornerRadius="5dp"
app:cardElevation="@dimen/margin_10">
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/margin_10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/filter"
android:textStyle="bold"
android:textColor="@color/colorGreen"
android:textSize="@dimen/font_large" />
<ImageView
android:id="@+id/img_cross"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/cross" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/margin_20"
android:background="@color/colorfaintGreen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_20"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/img_new"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/checkbox_tick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_10"
android:text="@string/New"
android:textColor="@color/colorText"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
<ImageView
android:id="@+id/img_Used"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="@dimen/margin_30"
android:src="@drawable/checkbox_tick_gray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_10"
android:text="@string/Used"
android:textColor="@color/colorText"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/margin_20"
android:background="@color/colorfaintGreen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_20"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="50"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="200"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="200+"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:layout_marginTop="@dimen/margin_20"
android:src="@drawable/filled_green" />
<SeekBar
android:id="@+id/seekbar"
style="@style/SeekBarWithoutSteps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
android:layout_marginTop="@dimen/margin_10"
android:max="4"
android:maxHeight="@dimen/margin_5"
android:minHeight="@dimen/margin_5"
android:paddingLeft="@dimen/margin_10"
android:paddingRight="@dimen/margin_10"
android:progressBackgroundTint="@color/colorGray"
android:progressTint="@color/colorGreen"
android:theme="@style/Widget.AppCompat.SeekBar.Discrete"
android:thumb="@drawable/filled_green"
android:thumbOffset="15dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/search_near_me_in_km"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="@dimen/btn_height"
android:layout_marginBottom="@dimen/margin_10"
android:layout_marginTop="@dimen/margin_10"
android:background="@drawable/btn_bg_green_rounded"
android:text="@string/submit"
android:textColor="@color/colorWhite"
android:textSize="@dimen/fontsize_medium" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Style.xml
------------------------------------------
<style name="MaterialDialogSheet" parent="@android:style/Theme.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowAnimationStyle">@style/MaterialDialogSheetAnimation</item>
</style>
<style name="MaterialDialogSheetAnimation">
<item name="android:windowEnterAnimation">@anim/popup_show</item>
<item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>
Add Animations in res folder:
anim/popup_show.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="0" />
</set>
anim/popup_hide.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="100%p" />
</set>
add a comment |
This answer could be helpful for you.
Android dialog width
add a comment |
@Override public void onStart()
super.onStart();
Dialog dialog = getDialog();
if (dialog != null)
dialog.getWindow()
.setLayout((int) (getScreenWidth(getActivity()) * .9), (int)(getScreenHeight(getActivity()) * .6) );
public static int getScreenWidth(Activity activity)
Point size = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(size);
return size.x;
public static int getScreenHeight(Activity activity)
Point size = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(size);
return size.y;
example of 90% width and 60% height
add a comment |
MyDialogFragment myDialogFragment =
new MyDialogFragment(activity,arraylist.get(position).getImage());
myDialogFragment.show();
Window window = myDialogFragment.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
Hi Suvarthee. Code only answers are considered low quality. Can you add an explanation of how your code works and how it addresses the problem in the question.
– Dijkgraaf
Nov 6 '18 at 6:57
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28513616%2fandroid-get-full-width-for-custom-dialog%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
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();
Oh i'm sorry sir. i'm update post title toAndroid get full width for custom Dialog
– DolDurma
Feb 14 '15 at 20:13
2
Just use the above code and make the width as 100%<item name="android:windowMinWidthMinor">100%</item>
– Psypher
Feb 14 '15 at 20:15
1
Thanks sir. i get this error now:windowMinWidthMinor requires API level 11 (current min is 8)
– DolDurma
Feb 15 '15 at 5:22
Perfectly what I was looking for!! THANKS
– Manza
Jan 9 '16 at 19:47
great its working for me as charm
– satvinder singh
Sep 16 '17 at 8:48
add a comment |
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();
Oh i'm sorry sir. i'm update post title toAndroid get full width for custom Dialog
– DolDurma
Feb 14 '15 at 20:13
2
Just use the above code and make the width as 100%<item name="android:windowMinWidthMinor">100%</item>
– Psypher
Feb 14 '15 at 20:15
1
Thanks sir. i get this error now:windowMinWidthMinor requires API level 11 (current min is 8)
– DolDurma
Feb 15 '15 at 5:22
Perfectly what I was looking for!! THANKS
– Manza
Jan 9 '16 at 19:47
great its working for me as charm
– satvinder singh
Sep 16 '17 at 8:48
add a comment |
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();
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();
edited Nov 22 '17 at 10:12
Kaushik
5,36452846
5,36452846
answered Feb 14 '15 at 18:56
PsypherPsypher
6,660114475
6,660114475
Oh i'm sorry sir. i'm update post title toAndroid get full width for custom Dialog
– DolDurma
Feb 14 '15 at 20:13
2
Just use the above code and make the width as 100%<item name="android:windowMinWidthMinor">100%</item>
– Psypher
Feb 14 '15 at 20:15
1
Thanks sir. i get this error now:windowMinWidthMinor requires API level 11 (current min is 8)
– DolDurma
Feb 15 '15 at 5:22
Perfectly what I was looking for!! THANKS
– Manza
Jan 9 '16 at 19:47
great its working for me as charm
– satvinder singh
Sep 16 '17 at 8:48
add a comment |
Oh i'm sorry sir. i'm update post title toAndroid get full width for custom Dialog
– DolDurma
Feb 14 '15 at 20:13
2
Just use the above code and make the width as 100%<item name="android:windowMinWidthMinor">100%</item>
– Psypher
Feb 14 '15 at 20:15
1
Thanks sir. i get this error now:windowMinWidthMinor requires API level 11 (current min is 8)
– DolDurma
Feb 15 '15 at 5:22
Perfectly what I was looking for!! THANKS
– Manza
Jan 9 '16 at 19:47
great its working for me as charm
– satvinder singh
Sep 16 '17 at 8:48
Oh i'm sorry sir. i'm update post title to
Android get full width for custom Dialog– DolDurma
Feb 14 '15 at 20:13
Oh i'm sorry sir. i'm update post title to
Android get full width for custom Dialog– DolDurma
Feb 14 '15 at 20:13
2
2
Just use the above code and make the width as 100%
<item name="android:windowMinWidthMinor">100%</item>– Psypher
Feb 14 '15 at 20:15
Just use the above code and make the width as 100%
<item name="android:windowMinWidthMinor">100%</item>– Psypher
Feb 14 '15 at 20:15
1
1
Thanks sir. i get this error now:
windowMinWidthMinor requires API level 11 (current min is 8)– DolDurma
Feb 15 '15 at 5:22
Thanks sir. i get this error now:
windowMinWidthMinor requires API level 11 (current min is 8)– DolDurma
Feb 15 '15 at 5:22
Perfectly what I was looking for!! THANKS
– Manza
Jan 9 '16 at 19:47
Perfectly what I was looking for!! THANKS
– Manza
Jan 9 '16 at 19:47
great its working for me as charm
– satvinder singh
Sep 16 '17 at 8:48
great its working for me as charm
– satvinder singh
Sep 16 '17 at 8:48
add a comment |
You need to get the current Window and set it's LayoutParams like so:
Dialog d=new Dialog(mContext,R.style.mydialog);
.........
.........
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);
that helped me , thanks
– mohnage7
Apr 11 '17 at 13:03
@MohNage7enjoy :)
– Abhishek Singh
Apr 12 '17 at 4:39
perfect answer!
– Amrutha Saj
Sep 14 '17 at 13:06
I never thoutht LayoutParams.MATCH_PARENT and LayoutParams.WRAP_CONTENT before. Thanks...
– Yusuf Çağlar
May 8 '18 at 16:13
1
The key here is to set it after calling show();. If you add it before this will not work. That was the issue with me. Thanks
– Vivek Mishra
Aug 25 '18 at 16:28
|
show 1 more comment
You need to get the current Window and set it's LayoutParams like so:
Dialog d=new Dialog(mContext,R.style.mydialog);
.........
.........
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);
that helped me , thanks
– mohnage7
Apr 11 '17 at 13:03
@MohNage7enjoy :)
– Abhishek Singh
Apr 12 '17 at 4:39
perfect answer!
– Amrutha Saj
Sep 14 '17 at 13:06
I never thoutht LayoutParams.MATCH_PARENT and LayoutParams.WRAP_CONTENT before. Thanks...
– Yusuf Çağlar
May 8 '18 at 16:13
1
The key here is to set it after calling show();. If you add it before this will not work. That was the issue with me. Thanks
– Vivek Mishra
Aug 25 '18 at 16:28
|
show 1 more comment
You need to get the current Window and set it's LayoutParams like so:
Dialog d=new Dialog(mContext,R.style.mydialog);
.........
.........
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);
You need to get the current Window and set it's LayoutParams like so:
Dialog d=new Dialog(mContext,R.style.mydialog);
.........
.........
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);
edited Nov 12 '18 at 4:19
answered Nov 21 '16 at 11:14
Abhishek SinghAbhishek Singh
3,69411434
3,69411434
that helped me , thanks
– mohnage7
Apr 11 '17 at 13:03
@MohNage7enjoy :)
– Abhishek Singh
Apr 12 '17 at 4:39
perfect answer!
– Amrutha Saj
Sep 14 '17 at 13:06
I never thoutht LayoutParams.MATCH_PARENT and LayoutParams.WRAP_CONTENT before. Thanks...
– Yusuf Çağlar
May 8 '18 at 16:13
1
The key here is to set it after calling show();. If you add it before this will not work. That was the issue with me. Thanks
– Vivek Mishra
Aug 25 '18 at 16:28
|
show 1 more comment
that helped me , thanks
– mohnage7
Apr 11 '17 at 13:03
@MohNage7enjoy :)
– Abhishek Singh
Apr 12 '17 at 4:39
perfect answer!
– Amrutha Saj
Sep 14 '17 at 13:06
I never thoutht LayoutParams.MATCH_PARENT and LayoutParams.WRAP_CONTENT before. Thanks...
– Yusuf Çağlar
May 8 '18 at 16:13
1
The key here is to set it after calling show();. If you add it before this will not work. That was the issue with me. Thanks
– Vivek Mishra
Aug 25 '18 at 16:28
that helped me , thanks
– mohnage7
Apr 11 '17 at 13:03
that helped me , thanks
– mohnage7
Apr 11 '17 at 13:03
@MohNage7enjoy :)
– Abhishek Singh
Apr 12 '17 at 4:39
@MohNage7enjoy :)
– Abhishek Singh
Apr 12 '17 at 4:39
perfect answer!
– Amrutha Saj
Sep 14 '17 at 13:06
perfect answer!
– Amrutha Saj
Sep 14 '17 at 13:06
I never thoutht LayoutParams.MATCH_PARENT and LayoutParams.WRAP_CONTENT before. Thanks...
– Yusuf Çağlar
May 8 '18 at 16:13
I never thoutht LayoutParams.MATCH_PARENT and LayoutParams.WRAP_CONTENT before. Thanks...
– Yusuf Çağlar
May 8 '18 at 16:13
1
1
The key here is to set it after calling show();. If you add it before this will not work. That was the issue with me. Thanks
– Vivek Mishra
Aug 25 '18 at 16:28
The key here is to set it after calling show();. If you add it before this will not work. That was the issue with me. Thanks
– Vivek Mishra
Aug 25 '18 at 16:28
|
show 1 more comment
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
);
2
Add setLayout() after setContentView() saved me! Thanks
– AvatarQing
Jan 30 '18 at 8:17
add a comment |
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
);
2
Add setLayout() after setContentView() saved me! Thanks
– AvatarQing
Jan 30 '18 at 8:17
add a comment |
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
);
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
);
edited Nov 21 '16 at 11:07
Martin Gottweis
2,355825
2,355825
answered Nov 21 '16 at 9:06
Hardeep KumarHardeep Kumar
6911
6911
2
Add setLayout() after setContentView() saved me! Thanks
– AvatarQing
Jan 30 '18 at 8:17
add a comment |
2
Add setLayout() after setContentView() saved me! Thanks
– AvatarQing
Jan 30 '18 at 8:17
2
2
Add setLayout() after setContentView() saved me! Thanks
– AvatarQing
Jan 30 '18 at 8:17
Add setLayout() after setContentView() saved me! Thanks
– AvatarQing
Jan 30 '18 at 8:17
add a comment |
In my case width of custom dialog shrinks in size(width) as the content inside dialog becomes smaller in width even though the the width property was set
android:layout_width="match_parent"
I just fixed that width to screen size and now its working according to my requirement
android:layout_width="320dp"
fixed my problem
– Ranjith Kumar
Apr 25 '17 at 13:24
add a comment |
In my case width of custom dialog shrinks in size(width) as the content inside dialog becomes smaller in width even though the the width property was set
android:layout_width="match_parent"
I just fixed that width to screen size and now its working according to my requirement
android:layout_width="320dp"
fixed my problem
– Ranjith Kumar
Apr 25 '17 at 13:24
add a comment |
In my case width of custom dialog shrinks in size(width) as the content inside dialog becomes smaller in width even though the the width property was set
android:layout_width="match_parent"
I just fixed that width to screen size and now its working according to my requirement
android:layout_width="320dp"
In my case width of custom dialog shrinks in size(width) as the content inside dialog becomes smaller in width even though the the width property was set
android:layout_width="match_parent"
I just fixed that width to screen size and now its working according to my requirement
android:layout_width="320dp"
answered Apr 17 '17 at 13:17
shehzyshehzy
90611131
90611131
fixed my problem
– Ranjith Kumar
Apr 25 '17 at 13:24
add a comment |
fixed my problem
– Ranjith Kumar
Apr 25 '17 at 13:24
fixed my problem
– Ranjith Kumar
Apr 25 '17 at 13:24
fixed my problem
– Ranjith Kumar
Apr 25 '17 at 13:24
add a comment |
In case anyone is wondering how to do it for a dialog shown using DialogFragment, you can override onCreateDialog to return a Dialog with custom style that has windowMinWidthMajor and minor set to 90%
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
return new Dialog(getActivity(), R.style.WideDialog);
Style:
<style name="WideDialog" parent="Base.Theme.AppCompat.Dialog">
<item name="android:windowMinWidthMajor">90%</item>
<item name="android:windowMinWidthMinor">90%</item>
</style>
add a comment |
In case anyone is wondering how to do it for a dialog shown using DialogFragment, you can override onCreateDialog to return a Dialog with custom style that has windowMinWidthMajor and minor set to 90%
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
return new Dialog(getActivity(), R.style.WideDialog);
Style:
<style name="WideDialog" parent="Base.Theme.AppCompat.Dialog">
<item name="android:windowMinWidthMajor">90%</item>
<item name="android:windowMinWidthMinor">90%</item>
</style>
add a comment |
In case anyone is wondering how to do it for a dialog shown using DialogFragment, you can override onCreateDialog to return a Dialog with custom style that has windowMinWidthMajor and minor set to 90%
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
return new Dialog(getActivity(), R.style.WideDialog);
Style:
<style name="WideDialog" parent="Base.Theme.AppCompat.Dialog">
<item name="android:windowMinWidthMajor">90%</item>
<item name="android:windowMinWidthMinor">90%</item>
</style>
In case anyone is wondering how to do it for a dialog shown using DialogFragment, you can override onCreateDialog to return a Dialog with custom style that has windowMinWidthMajor and minor set to 90%
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
return new Dialog(getActivity(), R.style.WideDialog);
Style:
<style name="WideDialog" parent="Base.Theme.AppCompat.Dialog">
<item name="android:windowMinWidthMajor">90%</item>
<item name="android:windowMinWidthMinor">90%</item>
</style>
answered Apr 30 '18 at 10:00
AmarghoshAmarghosh
48.5k1078112
48.5k1078112
add a comment |
add a comment |
Add code when you want to open dialog
final Dialog mBottomSheetDialog = new Dialog(getActivity(), R.style.MaterialDialogSheet);
mBottomSheetDialog.setContentView(R.layout.dialog_mainscreen_filter); // your custom view.
mBottomSheetDialog.setCancelable(true);
mBottomSheetDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
mBottomSheetDialog.getWindow().setGravity(Gravity.BOTTOM);
mBottomSheetDialog.show();
ImageView img_cross = mBottomSheetDialog.findViewById(R.id.img_cross);
final ImageView img_new = mBottomSheetDialog.findViewById(R.id.img_new);
final ImageView img_Used = mBottomSheetDialog.findViewById(R.id.img_Used);
img_cross.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
mBottomSheetDialog.dismiss();
);
img_new.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
img_new.setImageResource(R.drawable.checkbox_tick);
img_Used.setImageResource(R.drawable.checkbox_tick_gray);
);
img_Used.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
img_Used.setImageResource(R.drawable.checkbox_tick);
img_new.setImageResource(R.drawable.checkbox_tick_gray);
);
dialog's xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/colorWhite"
app:cardCornerRadius="5dp"
app:cardElevation="@dimen/margin_10">
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/margin_10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/filter"
android:textStyle="bold"
android:textColor="@color/colorGreen"
android:textSize="@dimen/font_large" />
<ImageView
android:id="@+id/img_cross"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/cross" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/margin_20"
android:background="@color/colorfaintGreen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_20"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/img_new"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/checkbox_tick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_10"
android:text="@string/New"
android:textColor="@color/colorText"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
<ImageView
android:id="@+id/img_Used"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="@dimen/margin_30"
android:src="@drawable/checkbox_tick_gray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_10"
android:text="@string/Used"
android:textColor="@color/colorText"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/margin_20"
android:background="@color/colorfaintGreen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_20"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="50"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="200"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="200+"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:layout_marginTop="@dimen/margin_20"
android:src="@drawable/filled_green" />
<SeekBar
android:id="@+id/seekbar"
style="@style/SeekBarWithoutSteps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
android:layout_marginTop="@dimen/margin_10"
android:max="4"
android:maxHeight="@dimen/margin_5"
android:minHeight="@dimen/margin_5"
android:paddingLeft="@dimen/margin_10"
android:paddingRight="@dimen/margin_10"
android:progressBackgroundTint="@color/colorGray"
android:progressTint="@color/colorGreen"
android:theme="@style/Widget.AppCompat.SeekBar.Discrete"
android:thumb="@drawable/filled_green"
android:thumbOffset="15dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/search_near_me_in_km"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="@dimen/btn_height"
android:layout_marginBottom="@dimen/margin_10"
android:layout_marginTop="@dimen/margin_10"
android:background="@drawable/btn_bg_green_rounded"
android:text="@string/submit"
android:textColor="@color/colorWhite"
android:textSize="@dimen/fontsize_medium" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Style.xml
------------------------------------------
<style name="MaterialDialogSheet" parent="@android:style/Theme.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowAnimationStyle">@style/MaterialDialogSheetAnimation</item>
</style>
<style name="MaterialDialogSheetAnimation">
<item name="android:windowEnterAnimation">@anim/popup_show</item>
<item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>
Add Animations in res folder:
anim/popup_show.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="0" />
</set>
anim/popup_hide.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="100%p" />
</set>
add a comment |
Add code when you want to open dialog
final Dialog mBottomSheetDialog = new Dialog(getActivity(), R.style.MaterialDialogSheet);
mBottomSheetDialog.setContentView(R.layout.dialog_mainscreen_filter); // your custom view.
mBottomSheetDialog.setCancelable(true);
mBottomSheetDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
mBottomSheetDialog.getWindow().setGravity(Gravity.BOTTOM);
mBottomSheetDialog.show();
ImageView img_cross = mBottomSheetDialog.findViewById(R.id.img_cross);
final ImageView img_new = mBottomSheetDialog.findViewById(R.id.img_new);
final ImageView img_Used = mBottomSheetDialog.findViewById(R.id.img_Used);
img_cross.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
mBottomSheetDialog.dismiss();
);
img_new.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
img_new.setImageResource(R.drawable.checkbox_tick);
img_Used.setImageResource(R.drawable.checkbox_tick_gray);
);
img_Used.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
img_Used.setImageResource(R.drawable.checkbox_tick);
img_new.setImageResource(R.drawable.checkbox_tick_gray);
);
dialog's xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/colorWhite"
app:cardCornerRadius="5dp"
app:cardElevation="@dimen/margin_10">
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/margin_10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/filter"
android:textStyle="bold"
android:textColor="@color/colorGreen"
android:textSize="@dimen/font_large" />
<ImageView
android:id="@+id/img_cross"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/cross" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/margin_20"
android:background="@color/colorfaintGreen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_20"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/img_new"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/checkbox_tick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_10"
android:text="@string/New"
android:textColor="@color/colorText"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
<ImageView
android:id="@+id/img_Used"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="@dimen/margin_30"
android:src="@drawable/checkbox_tick_gray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_10"
android:text="@string/Used"
android:textColor="@color/colorText"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/margin_20"
android:background="@color/colorfaintGreen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_20"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="50"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="200"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="200+"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:layout_marginTop="@dimen/margin_20"
android:src="@drawable/filled_green" />
<SeekBar
android:id="@+id/seekbar"
style="@style/SeekBarWithoutSteps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
android:layout_marginTop="@dimen/margin_10"
android:max="4"
android:maxHeight="@dimen/margin_5"
android:minHeight="@dimen/margin_5"
android:paddingLeft="@dimen/margin_10"
android:paddingRight="@dimen/margin_10"
android:progressBackgroundTint="@color/colorGray"
android:progressTint="@color/colorGreen"
android:theme="@style/Widget.AppCompat.SeekBar.Discrete"
android:thumb="@drawable/filled_green"
android:thumbOffset="15dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/search_near_me_in_km"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="@dimen/btn_height"
android:layout_marginBottom="@dimen/margin_10"
android:layout_marginTop="@dimen/margin_10"
android:background="@drawable/btn_bg_green_rounded"
android:text="@string/submit"
android:textColor="@color/colorWhite"
android:textSize="@dimen/fontsize_medium" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Style.xml
------------------------------------------
<style name="MaterialDialogSheet" parent="@android:style/Theme.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowAnimationStyle">@style/MaterialDialogSheetAnimation</item>
</style>
<style name="MaterialDialogSheetAnimation">
<item name="android:windowEnterAnimation">@anim/popup_show</item>
<item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>
Add Animations in res folder:
anim/popup_show.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="0" />
</set>
anim/popup_hide.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="100%p" />
</set>
add a comment |
Add code when you want to open dialog
final Dialog mBottomSheetDialog = new Dialog(getActivity(), R.style.MaterialDialogSheet);
mBottomSheetDialog.setContentView(R.layout.dialog_mainscreen_filter); // your custom view.
mBottomSheetDialog.setCancelable(true);
mBottomSheetDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
mBottomSheetDialog.getWindow().setGravity(Gravity.BOTTOM);
mBottomSheetDialog.show();
ImageView img_cross = mBottomSheetDialog.findViewById(R.id.img_cross);
final ImageView img_new = mBottomSheetDialog.findViewById(R.id.img_new);
final ImageView img_Used = mBottomSheetDialog.findViewById(R.id.img_Used);
img_cross.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
mBottomSheetDialog.dismiss();
);
img_new.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
img_new.setImageResource(R.drawable.checkbox_tick);
img_Used.setImageResource(R.drawable.checkbox_tick_gray);
);
img_Used.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
img_Used.setImageResource(R.drawable.checkbox_tick);
img_new.setImageResource(R.drawable.checkbox_tick_gray);
);
dialog's xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/colorWhite"
app:cardCornerRadius="5dp"
app:cardElevation="@dimen/margin_10">
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/margin_10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/filter"
android:textStyle="bold"
android:textColor="@color/colorGreen"
android:textSize="@dimen/font_large" />
<ImageView
android:id="@+id/img_cross"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/cross" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/margin_20"
android:background="@color/colorfaintGreen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_20"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/img_new"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/checkbox_tick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_10"
android:text="@string/New"
android:textColor="@color/colorText"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
<ImageView
android:id="@+id/img_Used"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="@dimen/margin_30"
android:src="@drawable/checkbox_tick_gray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_10"
android:text="@string/Used"
android:textColor="@color/colorText"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/margin_20"
android:background="@color/colorfaintGreen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_20"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="50"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="200"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="200+"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:layout_marginTop="@dimen/margin_20"
android:src="@drawable/filled_green" />
<SeekBar
android:id="@+id/seekbar"
style="@style/SeekBarWithoutSteps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
android:layout_marginTop="@dimen/margin_10"
android:max="4"
android:maxHeight="@dimen/margin_5"
android:minHeight="@dimen/margin_5"
android:paddingLeft="@dimen/margin_10"
android:paddingRight="@dimen/margin_10"
android:progressBackgroundTint="@color/colorGray"
android:progressTint="@color/colorGreen"
android:theme="@style/Widget.AppCompat.SeekBar.Discrete"
android:thumb="@drawable/filled_green"
android:thumbOffset="15dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/search_near_me_in_km"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="@dimen/btn_height"
android:layout_marginBottom="@dimen/margin_10"
android:layout_marginTop="@dimen/margin_10"
android:background="@drawable/btn_bg_green_rounded"
android:text="@string/submit"
android:textColor="@color/colorWhite"
android:textSize="@dimen/fontsize_medium" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Style.xml
------------------------------------------
<style name="MaterialDialogSheet" parent="@android:style/Theme.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowAnimationStyle">@style/MaterialDialogSheetAnimation</item>
</style>
<style name="MaterialDialogSheetAnimation">
<item name="android:windowEnterAnimation">@anim/popup_show</item>
<item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>
Add Animations in res folder:
anim/popup_show.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="0" />
</set>
anim/popup_hide.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="100%p" />
</set>
Add code when you want to open dialog
final Dialog mBottomSheetDialog = new Dialog(getActivity(), R.style.MaterialDialogSheet);
mBottomSheetDialog.setContentView(R.layout.dialog_mainscreen_filter); // your custom view.
mBottomSheetDialog.setCancelable(true);
mBottomSheetDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
mBottomSheetDialog.getWindow().setGravity(Gravity.BOTTOM);
mBottomSheetDialog.show();
ImageView img_cross = mBottomSheetDialog.findViewById(R.id.img_cross);
final ImageView img_new = mBottomSheetDialog.findViewById(R.id.img_new);
final ImageView img_Used = mBottomSheetDialog.findViewById(R.id.img_Used);
img_cross.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
mBottomSheetDialog.dismiss();
);
img_new.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
img_new.setImageResource(R.drawable.checkbox_tick);
img_Used.setImageResource(R.drawable.checkbox_tick_gray);
);
img_Used.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
img_Used.setImageResource(R.drawable.checkbox_tick);
img_new.setImageResource(R.drawable.checkbox_tick_gray);
);
dialog's xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/colorWhite"
app:cardCornerRadius="5dp"
app:cardElevation="@dimen/margin_10">
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/margin_10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/filter"
android:textStyle="bold"
android:textColor="@color/colorGreen"
android:textSize="@dimen/font_large" />
<ImageView
android:id="@+id/img_cross"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/cross" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/margin_20"
android:background="@color/colorfaintGreen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_20"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/img_new"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/checkbox_tick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_10"
android:text="@string/New"
android:textColor="@color/colorText"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
<ImageView
android:id="@+id/img_Used"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="@dimen/margin_30"
android:src="@drawable/checkbox_tick_gray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_10"
android:text="@string/Used"
android:textColor="@color/colorText"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/margin_20"
android:background="@color/colorfaintGreen" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_20"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="50"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="200"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="200+"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:layout_marginTop="@dimen/margin_20"
android:src="@drawable/filled_green" />
<SeekBar
android:id="@+id/seekbar"
style="@style/SeekBarWithoutSteps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
android:layout_marginTop="@dimen/margin_10"
android:max="4"
android:maxHeight="@dimen/margin_5"
android:minHeight="@dimen/margin_5"
android:paddingLeft="@dimen/margin_10"
android:paddingRight="@dimen/margin_10"
android:progressBackgroundTint="@color/colorGray"
android:progressTint="@color/colorGreen"
android:theme="@style/Widget.AppCompat.SeekBar.Discrete"
android:thumb="@drawable/filled_green"
android:thumbOffset="15dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/search_near_me_in_km"
android:textColor="@color/colorTextGray"
android:textSize="@dimen/fontsize_normal"
android:textStyle="bold" />
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="@dimen/btn_height"
android:layout_marginBottom="@dimen/margin_10"
android:layout_marginTop="@dimen/margin_10"
android:background="@drawable/btn_bg_green_rounded"
android:text="@string/submit"
android:textColor="@color/colorWhite"
android:textSize="@dimen/fontsize_medium" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Style.xml
------------------------------------------
<style name="MaterialDialogSheet" parent="@android:style/Theme.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowAnimationStyle">@style/MaterialDialogSheetAnimation</item>
</style>
<style name="MaterialDialogSheetAnimation">
<item name="android:windowEnterAnimation">@anim/popup_show</item>
<item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>
Add Animations in res folder:
anim/popup_show.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="0" />
</set>
anim/popup_hide.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="100%p" />
</set>
edited Dec 10 '18 at 10:45
answered Dec 10 '18 at 10:40
Pratibha SarodePratibha Sarode
866815
866815
add a comment |
add a comment |
This answer could be helpful for you.
Android dialog width
add a comment |
This answer could be helpful for you.
Android dialog width
add a comment |
This answer could be helpful for you.
Android dialog width
This answer could be helpful for you.
Android dialog width
edited May 23 '17 at 12:18
Community♦
11
11
answered Aug 24 '15 at 7:57
Rahul SharmaRahul Sharma
3,62111939
3,62111939
add a comment |
add a comment |
@Override public void onStart()
super.onStart();
Dialog dialog = getDialog();
if (dialog != null)
dialog.getWindow()
.setLayout((int) (getScreenWidth(getActivity()) * .9), (int)(getScreenHeight(getActivity()) * .6) );
public static int getScreenWidth(Activity activity)
Point size = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(size);
return size.x;
public static int getScreenHeight(Activity activity)
Point size = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(size);
return size.y;
example of 90% width and 60% height
add a comment |
@Override public void onStart()
super.onStart();
Dialog dialog = getDialog();
if (dialog != null)
dialog.getWindow()
.setLayout((int) (getScreenWidth(getActivity()) * .9), (int)(getScreenHeight(getActivity()) * .6) );
public static int getScreenWidth(Activity activity)
Point size = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(size);
return size.x;
public static int getScreenHeight(Activity activity)
Point size = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(size);
return size.y;
example of 90% width and 60% height
add a comment |
@Override public void onStart()
super.onStart();
Dialog dialog = getDialog();
if (dialog != null)
dialog.getWindow()
.setLayout((int) (getScreenWidth(getActivity()) * .9), (int)(getScreenHeight(getActivity()) * .6) );
public static int getScreenWidth(Activity activity)
Point size = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(size);
return size.x;
public static int getScreenHeight(Activity activity)
Point size = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(size);
return size.y;
example of 90% width and 60% height
@Override public void onStart()
super.onStart();
Dialog dialog = getDialog();
if (dialog != null)
dialog.getWindow()
.setLayout((int) (getScreenWidth(getActivity()) * .9), (int)(getScreenHeight(getActivity()) * .6) );
public static int getScreenWidth(Activity activity)
Point size = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(size);
return size.x;
public static int getScreenHeight(Activity activity)
Point size = new Point();
activity.getWindowManager().getDefaultDisplay().getSize(size);
return size.y;
example of 90% width and 60% height
answered Nov 19 '17 at 10:34
Pablo CegarraPablo Cegarra
2,69532541
2,69532541
add a comment |
add a comment |
MyDialogFragment myDialogFragment =
new MyDialogFragment(activity,arraylist.get(position).getImage());
myDialogFragment.show();
Window window = myDialogFragment.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
Hi Suvarthee. Code only answers are considered low quality. Can you add an explanation of how your code works and how it addresses the problem in the question.
– Dijkgraaf
Nov 6 '18 at 6:57
add a comment |
MyDialogFragment myDialogFragment =
new MyDialogFragment(activity,arraylist.get(position).getImage());
myDialogFragment.show();
Window window = myDialogFragment.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
Hi Suvarthee. Code only answers are considered low quality. Can you add an explanation of how your code works and how it addresses the problem in the question.
– Dijkgraaf
Nov 6 '18 at 6:57
add a comment |
MyDialogFragment myDialogFragment =
new MyDialogFragment(activity,arraylist.get(position).getImage());
myDialogFragment.show();
Window window = myDialogFragment.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
MyDialogFragment myDialogFragment =
new MyDialogFragment(activity,arraylist.get(position).getImage());
myDialogFragment.show();
Window window = myDialogFragment.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
edited Nov 6 '18 at 6:41
MJM
2,6781734
2,6781734
answered Nov 6 '18 at 6:37
Suvarthee ChakravartiSuvarthee Chakravarti
11
11
Hi Suvarthee. Code only answers are considered low quality. Can you add an explanation of how your code works and how it addresses the problem in the question.
– Dijkgraaf
Nov 6 '18 at 6:57
add a comment |
Hi Suvarthee. Code only answers are considered low quality. Can you add an explanation of how your code works and how it addresses the problem in the question.
– Dijkgraaf
Nov 6 '18 at 6:57
Hi Suvarthee. Code only answers are considered low quality. Can you add an explanation of how your code works and how it addresses the problem in the question.
– Dijkgraaf
Nov 6 '18 at 6:57
Hi Suvarthee. Code only answers are considered low quality. Can you add an explanation of how your code works and how it addresses the problem in the question.
– Dijkgraaf
Nov 6 '18 at 6:57
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28513616%2fandroid-get-full-width-for-custom-dialog%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown