Showing dialog on top of another running activity (Android)?

谁说我不能喝 提交于 2019-12-14 03:58:52

问题


I've created an application that works with another app on the Android platform. The other application passes my app information, with intents, based on user action. I was hoping, that I might be able to pop a translucent information dialog, on top of the other application. I followed one of the examples, here, but it brought my application back to the foreground and put the dialog on top of that. Is this possible? I'm hoping to avoid having to work with the other developers to set up intent listeners, and whatnot, to show my information.


回答1:


If you want to handle a popup on top of another activity, you must use broadcast listener for implementation. As far as translucent property is concerned, you can add the below line while instantiating a new dialog: dialog = new DialogBox(this, R.style.Transparent);

For implementing this, You need to write the following piece of code in styles.xml which will reside in values folder of the project.

      <style name="Transparent">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowAnimationStyle">
         @android:style/Animation.Translucent</item>
        <item name="android:windowBackground">@drawable/transparent</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:colorForeground">#fff</item>
      </style>

Similarly, You need to add the below line in colors.xml file present in values folder:

     <drawable name="transparent">#00000000</drawable>

Also, you can try this out: To Add Blur to the background image

     WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();  
     lp.dimAmount=0.0f;  
     dialog.getWindow().setAttributes(lp);  
     dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);  

Hope this will help.

Thanks!



来源:https://stackoverflow.com/questions/10031951/showing-dialog-on-top-of-another-running-activity-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!