Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android make a dialog appear in fullscreen

Tags:

I need the dialog to fill the screen except for some space at the top and the bottom. I've search for a solution but couldn't find one probably because I'm declaring it in an onClickListener. Can someone please give a solution?

Activity code:

sort.setOnClickListener(new View.OnClickListener() {              @Override             public void onClick(View v) {                 // TODO Auto-generated method stub                 AlertDialog.Builder sort = new AlertDialog.Builder(HomeScreen.this);                 // Get the layout inflater                 LayoutInflater inflater = HomeScreen.this.getLayoutInflater();                 View sortView = inflater.inflate(R.layout.sort_layout, null);                 sort.setView(sortView);                 sort.create().show();             }         }); 

XML:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:layout_marginBottom="50dp"     android:layout_marginTop="50dp"     android:background="@color/white"     android:orientation="vertical" android:layout_gravity="center">     + some more stuff here I dont think it's relevant </LinearLayout> 

enter image description here

like image 715
Mihai Bratulescu Avatar asked Aug 19 '13 13:08

Mihai Bratulescu


People also ask

How to make full screen custom dialog in Android?

This example demonstrate about How to make full screen custom dialog. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.

How do I make my dialog fragment full screen?

setTransition(FragmentTransaction. TRANSIT_FRAGMENT_OPEN); // To make it fullscreen, use the 'content' root view as the container // for the fragment, which is always the root view for the activity transaction. add(android. R.

How do I change the dialog size in Android?

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.


2 Answers

here set your screen width and width to the dialog

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();     lp.copyFrom(dialog.getWindow().getAttributes());     lp.width = width;     lp.height = height;     dialog.getWindow().setAttributes(lp); 

or in your styles create a style like this then

 <style name="DialogTheme" parent="android:Theme.Dialog">      <item name="android:layout_width">fill_parent</item>     <item name="android:layout_height">fill_parent</item>       <!-- No backgrounds, titles or window float -->     <item name="android:windowBackground">@null</item>     <item name="android:windowNoTitle">true</item>     <item name="android:windowIsFloating">false</item> </style> 

create a dialog object like this

dialog = new Dialog(this, R.style.DialogTheme); 

Edit ::

get width and height like this for any device it will fills..

WindowManager manager = (WindowManager) getSystemService(Activity.WINDOW_SERVICE);     int width, height;     LayoutParams params;      if (Build.VERSION.SDK_INT > VERSION_CODES.FROYO) {         width = manager.getDefaultDisplay().getWidth();         height = manager.getDefaultDisplay().getHeight();     } else {         Point point = new Point();         manager.getDefaultDisplay().getSize(point);         width = point.x;         height = point.y;     } 
like image 175
kalyan pvs Avatar answered Sep 19 '22 14:09

kalyan pvs


first Make custom style for dialog in style.xml file:

<style name="full_screen_dialog" parent="@android:style/Theme.Dialog">     <item name="android:windowNoTitle">true</item>     <item name="android:windowFullscreen">true</item>     <item name="android:windowIsFloating">true</item>     <item name="android:windowContentOverlay">@null</item>     <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>     <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>     <item name="android:windowBackground">@android:color/transparent</item> </style> 

Then after set this theme to your Alert Dialog:

 AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this,  R.style.full_screen_dialog)); 

Or You can call new Activity and Give this Custom style to that activity as a theme in your manifest file...

like image 35
Piyush Avatar answered Sep 18 '22 14:09

Piyush