How to disable any event on a View in Android?

android, android-layout, android-view

Solution

Simply put a view on top of your view. You can toggle it on off by setting view.visibility = gone/visible.

<FrameLayout>
<WebView/>
<FrameLayout This view will be on top/>
</FrameLayout>

Edit: Just stumpled upon this link: https://stackoverflow.com/a/3856199/969325 Basically disables all touch event for the webview. Tryed that?

Edit 2 reedit: Try to set the visibility to gone for the the top view below your listview.

Problem

My question is simple: How to disable any event on a View in Android? (including removing its focussability, like I just want it to be there visually but be inexistant on everything else) And does it work on a whole view tree? (like if I disable events on the root, all the events will be disabled for its children?). Now, before you say anything I have tried all the following: - setEnabled - setFocusable - setSelected - setClickable - setActivated And none of these methods appear to work, seriously. I have tried them directly on a `WebView`, as well as on the parent layout on everything but I am still able to interact with it. Any idea? Thanks! EDIT#1 The solution that consists in adding a view on top of the view that needs to be disabled doesn't work. Actually, it's still possible to click on the inner view, I have tried with a simple example: ``` <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#ff0000"> <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="match_parent" android:text="Click Me!" /> </LinearLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00000000" /> </FrameLayout> ``` Here it's still possible to click on the `button`. EDIT#2 The reason why I want to do this is related to the following question that I asked weeks ago. What I have is a `ListView`acting as a navigation bar which is underneath a `View` that holds the content of my app. The problem with this implementation is that when I try to scroll through the `ListView` when there is a focusable view in the layer on top of it, well the `ListView` doesn't scroll and instead it's the top view that takes focus (That's the case when there is a `Webview` or an `EditText` etc.). So yes as mentioned in one of the answers, I can disable any click events on a `WebView` by overriding `setOnTouchListener` but the view remains focussed and I think this is the reason why I am still having the same issue with my navigation bar.

Original source

Related problems