1

I wanna create a custom PopupWindow similar to this :

http://android-er.blogspot.kr/2012/03/example-of-using-popupwindow.html

In this example, PopupWindow is created by a button click event from an activity, but i want to create PopupWindow via intent from another application. Is it possible? Any comments will be very appreciated!

Nari Kim Shin
  • 2,459
  • 1
  • 25
  • 33
  • Reffer this link may it helps you..[link1][1] And also look at this..[link2][2] [1]: http://stackoverflow.com/questions/2231438/progress-dialog-while-starting-new-activity [2]: http://stackoverflow.com/questions/4805845/how-to-open-an-activity-in-a-popup-window – AndiM Apr 15 '13 at 05:22

3 Answers3

3

The idea is to declare a standard Activity to make it appear like a Popup window of sorts.

Use this code (standard boiler plate Intent code to trigger the Activity)

SOME_WIDGET.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        Intent myIntent = new Intent(getApplicationContext(), THE_POPUP_ACTIVITY.class);
        startActivity(myIntent);
    }
});

If, for example, you name the popup Activity as Popup, then replace the THE_POPUP_ACTIVITY.class with Popup.class

Now, for this Activity, in the Manifest, declare a theme. For example:

And this is the corresponding style declaration:

<style name="DialogNoTitleBar" parent="android:style/Theme.Dialog">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

Also, in the onCreate() of the Popup Activity, you might want to add this statement right after the setContentView(R.layout.THE_LAYOUT_XML); I say might because how you want it to appear may vary from how I program my popup Activity.

getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
Siddharth Lele
  • 27,623
  • 15
  • 98
  • 151
  • Thanks, IceMAN!! I applied this customized theme to my Activity, but still can't get what i wanted. I think i should use "PopupWindow", cuz my popup should be appeared while focus is changing to other activity or view. Btw, i got a lot of insighs from your comments! Thank you! – Nari Kim Shin Apr 15 '13 at 07:30
  • @NariKim: The _solution_ I have posted is not how you want it to look. Naturally, my code will differ with your requirement. What I was offering was a pointer on how to go about achieving exactly what you need. Keeping in mind, of course, that you will have to do your own customization's. _Also i want to interacted with base activity without dismiss popup!_ This is not possible regardless of which method / solution you choose to use. You can pass extras in the `Intent` as you do normally, but beyond that, `PopupWindow` or a solution like mine will always take the focus away. – Siddharth Lele Apr 15 '13 at 08:34
  • Thank you for your comment. I think my original question was little bit ambiguous. I left more description at @AndyFaizan's answer, and i found the solution. By using `service` i can get intent without UI(or Activity), and according to this [link](http://developer.android.com/reference/android/widget/PopupWindow.html) i can maintain focus on my popup without dissmiss. – Nari Kim Shin Apr 16 '13 at 03:28
  • @NariKim: I think you misunderstand my comment. This is part of your comment in Jashan's post: _Also i want to interacted with base activity without dismiss popup_. This is the crux of it which I said is not possible and will loose focus: **interacted with base activity**. It goes without saying that the popup will **naturally** get the focus since that is now active on the screen. – Siddharth Lele Apr 16 '13 at 04:06
1

Your requirement isn't really clear. Intents are usually used when you want to switch to another activity or maybe send the intent to a service of some sorts. If you want to open a dialog for an action, you don't really need intents.

AndyFaizan
  • 1,833
  • 21
  • 30
  • Thank you for your comment Andy! I'm currently making an independent library which can be used from another applications. In my library, i have several components and want to show these components by popupWindow, not dialog. So my scenario is like this. In application side, they can send an intent to my library, and in my library, an activity will get this intent, and show PopupWindow according to intent msg. Also i wanna show only the PopupWindow, not activity, is it make sense? – Nari Kim Shin Apr 15 '13 at 05:15
  • Ok. In that case I guess IceMan's answer is pretty much the way to go. – AndyFaizan Apr 15 '13 at 05:25
0

Create an activity with your custom design, while registering the activity in the manifest file just add this android:theme="@android:style/Theme.Dialog" and call the activity with your intent. Hope you got it. :)

Jashan PJ
  • 4,177
  • 4
  • 27
  • 41
  • Thank you Jashan! I've tried your suggestion, and it looks quite similar to what i expected. But i have one more question. Is it possible to change its popup location or add some animation effects on this? Also i want to interacted with base activity without dismiss popup! :) – Nari Kim Shin Apr 15 '13 at 05:36
  • Ya i think its possible. Just check this blog http://android-codes-examples.blogspot.in/2011/04/animated-customized-popup-transparent.html and aslo this question http://stackoverflow.com/questions/7478417/positon-an-acitvity-applied-with-a-theme-dialog-at-a-particular-x-y-position may it will help you.. – Jashan PJ Apr 15 '13 at 10:25