How to Get a Dialog Style Activity Window to Fill the Screen

How can I get a Dialog style activity window to fill the screen?

I found the solution:

In your activity which has the Theme.Dialog style set, do this:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.your_layout);

getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}

It's important that you call Window.setLayout() after you call setContentView(), otherwise it won't work.

How to show an Activity as a dialog box rather than a new screen?

In your AndroidManifest manifest file define your activity like this :

<activity android:theme="@android:style/Theme.Dialog"
android:excludeFromRecents="true" />

and If you want your activity to not be cancelable when the user clicks outside it just add the following line in your Activity.Java file inside onCreate method :

this.setFinishOnTouchOutside(false);

Android make a dialog appear in fullscreen

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;
}

How to set Full screen dialog with dialog fragment

Create a theme in your style.xml which extends from Theme.AppCompat.Light.DarkActionBar, something like below:

<style name="DialogFragmentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

<item name="android:paddingRight">0dp</item>
<item name="android:paddingLeft">0dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:windowNoTitle">true</item>
</style>

and set the style you created while opening the dialog, something like below:

CustomDialogFragment mDialog = new CustomDialogFragment();
...
mDialog.setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogFragmentTheme);
mDialog.show(getSupportFragmentManager(), "DialogFragment");

Custom Dialog in full screen?

Give its constructor a non-dialog theme, such as android.R.style.Theme or android.R.style.Theme_Light.

Code by @Bob.

Dialog dialog = new Dialog(context, android.R.style.Theme_Light); 
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.MyCustomDialogLayout);
dialog.show();

android: layout: How to make my dialog box fill the screen with the XML

As I understand it the issue that the solution to How can I get a Dialog style activity window to fill the screen? solved was that the layout had to be modified after the xml had been loaded. Basically there is no xml that can do this alone.



Related Topics



Leave a reply



Submit