Align an activity as dialog on top left - android

i know this question was asked for aligning a dialog on the left,
but here i'm using an activity with a
android:theme="#android:style/Theme.Dialog" and the problem is that it's display at the center of the screen and i want to display on the top left corner.
is there any way to do so ?
i have tried using the android:layout_gravity="top|left" on my concerned activity .xml but that doesn't work.
Thank you for your help

Try this on your onCreate of dialog activity
WindowManager.LayoutParams wmlp = getWindow().getAttributes();
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
Hope it helps.

Related

how to display dialog builder in front of floating window

Hi....
I have an activity and a service in which in this service I am running a
windowmanager dialog (floating window)
Purpose of this is that.
I want to display this window every activity I visit so this floating window can also me minimize just like facebook messager except fb messenger is another application from facebook
then there are scenario that I want to display a dialog builder in my app my the problem is that since I am using floating window the dialog I display wont display in front of floating instead it just display at the back since I know floating window is also a dialog and my dialog display at the back of floating window,
my question is that is there any way to display my dialog in front of floating window?
I also tried displaying another floating window it's works but it will cause a lot of problem also
thanks for the help in future!
You can use WindowManager. WindowManager
For example, you can write code. Like this,
View v; // your dialog view
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,0,0,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP;
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
windowManager.addView(v, params);
Maybe you need permission,
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

Is there a SoftInputMode workaround to show whole dialog

I have a DialogFragment with two EditText fields and another field with an ImageView to increment its value underneath these, they all live in a ScrollView.
The problem is neither adjust mode for the soft keyboard shows my entire DialogFragment at once, despite there being space.
adjustResize causes the ScrollView to resize and hide the bottom row. adjustpan keeps the ScrollView size intact but the soft keyboard overlaps the bottom row.
Removing the ScrollView means either option causes the keyboard to overlap.
What I would like is for the DialogFragment to move up the screen without resizing. Can I make that happen? Ideally I'd like to keep the ScrollView in my Layout to better support very small screens.
The only solution I found was to change the window options for the dialog fragment itself. Obviously on a smaller screen this will still be an issue so I am still looking for a better answer.
#Override
#NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
//I was using android.R.style.Theme_Translucent_NoTitleBar for another issue
//but I don't think the theme makes any difference to how the window is laid out
//that is relevant to the below code
Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent_NoTitleBar);
... //Do your usual stuff here
dialog.getWindow().setContentView(...);
final WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.gravity = Gravity.TOP; //this is the important part
dialog.setCanceledOnTouchOutside(false);
return dialog;
}

Android Activity with Transparent Layout

I wish to create a activity that look like a popup window
That is with transparent background for activity als i wish to show it in custom position on scree that is on right corner of device screen
what i did was inside onCreate of pop over like activty
Display display = getWindow().getWindowManager().getDefaultDisplay();
WindowManager.LayoutParams params = getWindow().getAttributes();
// params.x = -20;
params.height = (display.getHeight()) / 2;
params.width = (display.getWidth()) / 2;
// params.y = -10;
params.gravity = Gravity.RIGHT;
getWindow().setAttributes(params);
in maifest
<activity android:name=".DialogAct"
android:theme="#android:style/Theme.Holo.Light.NoActionBar"></activity>
This is what my launcher activity looks like
So when i click on search on action bar i'm sending intent to my new activity .I want to make it look like pop just below the search icon
This what i obtained is
You can see search of previous activity is clicked and new activity is loaded(blue portion).
As you can see the new activity moves to centre of screen . but i want it just below the action bar icon.
i tried params.gravity = Gravity.TOP | Gravity.RIGHT;. then i got this
I want to place it just below the action bar of previous activity . I tried many ways to achieve it but failed. so can anyone suggest a methode
In your manifest you wrote
<activity android:name=".DialogAct"
android:theme="#android:style/Theme.Holo.Light.NoActionBar">
you should remove the NoActionBar part
<activity android:name=".DialogAct"
android:theme="#android:style/Theme.Holo.Light">
I can think of two things that may help. First, you could try changing the Theme in your manifest to android:theme="#android:style/Theme.Dialog and this should give you the wanted look.
Edit
You can hide the title bar with
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
just make sure to call it before calling setContentView()
Also, if it doesn't need to be a separate Activity you could use PopupWindow. With this you can use isAboveAnchor and use the ActionBar as the anchor and place it below or use one of the other associated methods. I don't know if either of these will fulfill what you need but they may work for you.
#edwin What you can do is after making
params.gravity = Gravity.TOP | Gravity.RIGHT;
you just provide some margin from top, like this:
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(left, top, right, bottom);
yourCustomPopOveractivity.setLayoutParams(params);
and i think after doing this you can get your needed position and everything you just did is right.
Please try then tell me
Try Gravity to Center rather than Top Right..

Preventing an activity from occupying the full width of the screen

I have a dialog-style android activity that gets displayed on top of the main activity in my android app. I don't want it to take up the full width of the screen. How can I specify that it leaves a margin of x dp on either side of it?
Two solutions:
you can set the margin manually as said by #Raghunandan there.
you could set a custom theme to that particular activity which by default doesn't take up the full screen space. for that particular activity just add
<activity android:theme="#android:style/Theme.Dialog">
Try this code
LayoutParams lp = this.getWindow().getAttributes();
lp.x=50;lp.y=20;lp.width=100;lp.height=200;lp.gravity=Gravity.TOP | Gravity.LEFT;
lp.dimAmount=0;
lp.flags=LayoutParams.FLAG_LAYOUT_NO_LIMITS | LayoutParams.FLAG_NOT_TOUCH_MODAL;
this.setContentView(view, lp);

Anchor Android Dialog to a View

I wanted to know if it is possible to anchor a Dialog to a View in Android, or in general: just to display the dialog at a certain location on the screen.
P.S.
I don't want to use a PopupMenu because it is my understanding that one cannot customize the items displayed in the menu-- I'm ultimately trying to have text and put an image next to it to alert the user that they have a message or something new to see here.
Thanks for your time-
Use Window params.
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.copyFrom(getDialog().getWindow().getAttributes());
params.gravity = Gravity.BOTTOM;
params.y = YOUR_ANCHOR_VIEW.getHeight();
getDialog().getWindow().setAttributes(params);
I used Gravity.BOTTOM and view height to anchor dialog on top of anchor view.
Gravity.TOP will make y to apply from top and vise versa.
I used this code on onActivityCreated().

Categories

Resources