[英]How to blur the Parent Activity when a fragment is added?
An Activity which has an image when i click the image 单击图像时具有图像的活动
1)A fragment should be added in the middle of the parent activity 1)应该在父活动的中间添加一个片段
2)When the fragment appears the background of parent activity should get blurred/dimmed. 2)当片段出现时,父母活动的背景应该变得模糊/变暗。
3)And clicking outside the fragment the fragment should disappear again. 3)然后在片段外单击,片段应再次消失。
(Same effect we get when we click contact image in whatsApp it opens an overlay) I have can add fragment successfully but the activity remains active. (当我们在whatsApp中单击联系人图像时,它会打开一个叠加层,效果相同。)我可以成功添加片段,但活动仍处于活动状态。
How to achieve this effect? 如何达到这个效果? I have tried fragmentTransaction.setCustomAnimation(int,int) but it does not work.
我试过fragmentTransaction.setCustomAnimation(int,int),但是不起作用。
Thank you. 谢谢。
You have two options: 您有两种选择:
DialogFragment
setting the layout in the onCreateView()
method. DialogFragment
在onCreateView()
方法中设置布局。 Fragment
with a background with alpha (for example #44000000
). Fragment
(例如#44000000
)。 Add the OnTouchListener
to the background view and in the onTouch()
method, dismiss the Fragment
. OnTouchListener
添加到背景视图中,然后在onTouch()
方法中关闭Fragment
。 By the way, I would seriously recommend you the first option. 顺便说一句,我会认真推荐您第一个选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.