6

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:

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 ListViewacting 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.

Community
  • 1
  • 1
Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158

1 Answers1

6

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.

Community
  • 1
  • 1
Warpzit
  • 27,966
  • 19
  • 103
  • 155
  • 1
    I don't want it to disappear! I just want to disable any event (like clicks) on it... – Amokrane Chentir May 07 '12 at 11:46
  • @AmokraneChentir just make it transparent... android:background="android:color/transparent" <-- if it exists, else create you own transparent color – Warpzit May 07 '12 at 11:49
  • Oh ok, I didn't read your answer properly. Well actually even with another view on top of it, I am still able to click through it on the inner view. – Amokrane Chentir May 07 '12 at 12:28
  • @AmokraneChentir Okay, will try to experiment a little. Is it a webview which gives you troubles? Is it flash that gives problems? – Warpzit May 07 '12 at 12:33
  • It's a Webview. I am testing too on an experimental project (just with basics views). Thanks for your help. – Amokrane Chentir May 07 '12 at 12:36
  • @AmokraneChentir stumpled upon alternative: http://stackoverflow.com/a/3856199/969325 – Warpzit May 07 '12 at 13:19
  • Yeah I just saw it. But it doesn't solve my particular problem wich is more complex than that and comes to the difference between `focus` and `click`. Anyway, you can udpate your answer with this and I'll +1 it :) – Amokrane Chentir May 07 '12 at 13:20