clickable
seems to be useful when you need a view to consume clicks so that they do not go to views beneath the top view.
For example, I have a FrameLayout
that I display over an underlying RelativeLayout
at certain times. When the user would click on an underlying EditText
the focus would shift to that EditText
. Really annoying when the FrameLayout
was still being shown. Now the user doesn't know why a keyboard just popped up or where they are typing.
When I set clickable="true"
in the FrameLayout
, users could no longer accidentally click underlying EditText
fields.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<EditText>
<EditText>
<EditText>
<!-- FrameLayout with grayed-out background. -->
<FrameLayout
android:id="@+id/sometimes_visible_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80808080"
android:clickable="true"
android:visibility="gone"
android:focusable="true"
...>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
...>
<View>
<View>
</LinearLayout>
</FrameLayout>
</RelativeLayout>