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..
Related
I'm trying to add two decorations to a ViewPager. One, PageIndicator, is a custom decoration I made, and the other is a standard PagerTitleStrip.
Adding these as the ViewPager's children in the XML doesn't do anything, and at least the PageIndicator's constructor doesn't even get called. So, I'm currently using this bit of code:
mPageIndicator = new PageIndicator(this);
PagerTitleStrip strip=new PagerTitleStrip(this);
float d=getResources().getDisplayMetrics().density;
ViewPager.LayoutParams params = new ViewPager.LayoutParams();
params.isDecor = true;
params.gravity = Gravity.BOTTOM;
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
mPageIndicator.setLayoutParams(params);
ViewPager.LayoutParams params2=new ViewPager.LayoutParams();
params2.isDecor = true;
params2.gravity = Gravity.BOTTOM;
params2.height= (int) (20*d);
strip.setLayoutParams(params2);
mViewPager.addView(strip);
mViewPager.addView(mPageIndicator);
This gets executed during my activity's onStart, because I'm showing a splash screen with the same activity and calling setContentView in onStart.
This makes both decorations visible at the bottom of the view, but the title strip doesn't show any text before the view is swiped once, and swiping back shows the first page title. This behavior repeats whenever mViewPager's setAdapter is called. I have tried calling setCurrentItem twice when the adapter is set, but that doesn't seem to help.
How do I work around this?
As CommonsWare pointed out, this is a bug with appcompat-v4 23.0.1. I managed to solve this by returning to support appcompat-v7 and appcompat-v4 version 22.2.0.
This answer to a duplicate question offers an alternative solution.
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.
I want to make a floating layout appears on all screens of any apps on the phone, and I can make actions on this layout besides other app running beside this layout can receive it's own actions and events
And here is an app which do what I want https://play.google.com/store/apps/details?id=com.ninja.sms
Here is the approach which I have worked on:
I used WindowManager to draw the layout on and a service to manage this layout.
I used the following library https://github.com/t0mm13b/TouchSoftly but it has some problems
1. The layout doesn't receive actions or touch events, the actions goes to the views under the one which drawn by this library.
2. The layout disappear when the activity which launched the service killed.
So, I have made some customization on it in the following snippet
_layOutParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
_layOutParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
_layOutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
_layOutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
if (_layOutParams != null) {
Log.d(TAG, "onCreate() - Got _layOutParams!");
_layOutParams.gravity = Gravity.RIGHT | Gravity.TOP;
} else
Log.d(TAG, "onCreate() - _layOutParams is null! :(");
_hudPageView = _layOutInflater.inflate(R.layout.service_hudpageview, null);
The result is that : the layout already drawn and can get touch event but the Home, Back and Recent apps buttons doesn't work or have any effect on any app while the layout appear on the screen.
So still doesn't achieve what I want.
And Here is the source code and repository which I am working on, so u can review my source code
https://github.com/mmelsabry/FloatingLayout
I know there is another question here Floating widget / Overlay on Android launcher
but it doesn't help
Try using TYPE_SYSTEM_OVERLAY instead of TYPE_SYSTEM_ALERT.
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);
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().