Dmitry Zaitsev Dmitry Zaitsev - 1 year ago 84
Android Question

Fragment over another fragment issue

When I'm showing one fragment (which is full screen with

background) over another fragment (let's call it main), my main fragment still reacts to clicks (we can click a button even if we don't see it).

Question: how to prevent clicks on first (main) fragment?


Unfortunately, I can't just hide main fragment, because I'm using transparent background on second fragment (so, user can see what located behind).

Answer Source

Set clickable property on the second fragment's view to true. The view will catch the event so that it will not be passed to the main fragment. So if the second fragment's view is a layout, this would be the code:

<LinearLayout xmlns:android=""
    android:clickable="true" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download