7

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

enter image description here

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 enter image description here

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

enter image description here

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

edwin
  • 7,985
  • 10
  • 51
  • 82

4 Answers4

0

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">
Onur A.
  • 3,007
  • 3
  • 22
  • 37
  • if give so it will display title bar in my activity . i doesn't want to show that – edwin Jul 24 '13 at 13:09
  • but in your question you say you want it to below the action bar, how can you detect whether it is below action bar if you dont use an action bar? – Onur A. Jul 24 '13 at 13:15
  • well that's my problem the blue are in screen shot is an activity. with out title bar /action bar and what you seen behind that is previous activity which navigate to the this activity . – edwin Jul 24 '13 at 13:26
  • i dont get you, you want actionbar or not ? and if you dont want, how it will be possible to position your popup below action bar? it makes no sense – Onur A. Jul 24 '13 at 13:30
  • what do you have when you try to remove params.gravity = Gravity.TOP | Gravity.RIGHT; – Onur A. Jul 25 '13 at 06:54
0

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.

codeMagic
  • 44,549
  • 13
  • 77
  • 93
  • i try changing my theme but it doesn't help it bring out the title bar. that should be avoided in my case .I can't go for popover since there many fragment transactions are going to happening in my activity. so i need a full control over it. Thant's why i took this approach – edwin Jul 24 '13 at 13:24
  • If the title bar is your only problem with the first solution then see my edit. That will allow you to hide the title bar – codeMagic Jul 24 '13 at 13:32
  • I tried it .but still not able to achieve what i needed . can please check the edit . – edwin Jul 25 '13 at 04:34
  • Solved it in my own way creating custom theme. thanks for your guidance – edwin Jul 25 '13 at 05:25
  • You're welcome. I'm glad you solved it. If none of these answers helped you can post your own solution and accept it – codeMagic Jul 25 '13 at 12:37
0

@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

Deepika Lalra
  • 1,035
  • 1
  • 10
  • 24
  • FIRST OF ALL THANKS FOR YOUR EFFORT .ACTUALLY I FOUND OUT SOLUTION FOR THIS AFTER POSTING THE QUESTION IN ANOTHER WAY THROUGH A SMALL WORKAROUND IN XML. – edwin Oct 25 '13 at 11:31
  • @edwin Oh great! you found the answer. So please provide your solution here and if my answer is also right and useful then please vote for answer or make answer accepted so that if anyone is facing the same problem can find the answer here. :) – Deepika Lalra Oct 28 '13 at 06:00
-1

Try Gravity to Center rather than Top Right..

Armaan Stranger
  • 3,140
  • 1
  • 14
  • 24