I created an non-maximized activity using android:theme="@android:style/Theme.Dialog" to make it looks like a dialog. I need to change the position of the activity on screen but I didn't find how to do this...
when a dialog is shown or it's window comes visible on top of an existing activity, then it overrides partial the activity window so existing activity will move to partially invisible state and you will get call to onPause() from ActivityThread. but to be sure we also need to consider here a one think...
A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed. Dialog Design.
To change the position (with the theme set to Theme.Dialog
), you can override the gravity, size and coordinates of the LayoutParams of your activity's decor view after it has been attached to the window. Here's an example:
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
View view = getWindow().getDecorView();
WindowManager.LayoutParams lp = (WindowManager.LayoutParams) view.getLayoutParams();
lp.gravity = Gravity.LEFT | Gravity.TOP;
lp.x = 10;
lp.y = 10;
lp.width = 300;
lp.height = 300;
getWindowManager().updateViewLayout(view, lp);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With