4

I have created transparent fragment overlay tutorial on activity and I want to disable touch event of background activity shown below transparent fragment. so user can not touch anything from activity and just use fragment help tutorial.

Thank you in advance

jil123
  • 99
  • 1
  • 12

2 Answers2

12

If you are using an fragment over an activity that is set to full screen ie match_parent. Then in the fragments root layout you can set an attribute android:clickable="true" to consume click events. By default layouts such as RelativeLayout , LinearLayout etc don't consume click events. Other views such as Button and TextView have this on by default.

In your overlay fragment.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    android:clickable="true">

</RelativeLayout>
Eoin
  • 4,050
  • 2
  • 33
  • 43
  • Thank you so much...your solution works for me... all view's touch event is disabled except navigation drawer... can you help me to solve that...??@Modge – jil123 Oct 14 '15 at 06:52
  • make sure the layout is below your toolbar and it should be ok – Eoin Oct 14 '15 at 06:54
  • Im not sure there, maybe you might have to use a layout by itself without no fragment – Eoin Oct 14 '15 at 07:28
0

Or just find the parent view of fragment by id... and set the onClick listener on it.. Done.

SRB Bans
  • 3,096
  • 1
  • 10
  • 21