AppBarLayout marked with height = 0dp does not respond to touch events (click)

I used the AppBarLayout inside the CoordinatorLayout , in my application. Due to certain design requirements, I was forced to remove the shadow below the AppBarLayout element by setting its elevation property to 0. ( app:elevation="0" ). After that, the elements inside the AppBarLayout, the tabs do not respond to touch / click events.

By setting the height back to 1dp, the elements respond to touch / click events, but then I go back to the shadow ...

Does anyone have a suggestion on how to get elements to respond to touch / click events, and AppBarLayout is at 0dp ?

Code output:

  <android.support.design.widget.CoordinatorLayout android:id="@+id/rootLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="@dimen/app_bar_height" app:elevation="0dp"> <android.support.v7.widget.Toolbar android:id="@+id/my_toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize"> <ImageView android:layout_width="wrap_content" android:layout_height="45dp" android:scaleType="fitCenter" android:layout_gravity="center" android:id="@+id/toolbar_logo" android:maxHeight="45dp" android:contentDescription="Main logo"/> </android.support.v7.widget.Toolbar> <android.support.design.widget.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:tabIndicatorColor="@color/tab_indicator_color" app:tabTextColor="@color/primary_text_grey" app:tabIndicatorHeight="3dp" android:id="@+id/tab_layout"> </android.support.design.widget.TabLayout> </android.support.design.widget.AppBarLayout>....... 
+5
source share
2 answers

Solved by replacing the CoordinatorLayout element with LinearLayout with android:orientation="vertical" . Using CoordinatorLayout seems to have been the wrong approach to this.

+1
source

Want to close the loop on this since I ran into very similar problems.

The problem is not that elevation = 0dp, the problem is that CoordinatorLayout behaves similarly to FrameLayout, that is, elements declared in XML later are "on top" of previously declared elements. The change to the linear layout has occurred because it does not support "overlapping elements".

The correct solution is to move your AppBarLayout (or any element) on top of the fact that any element is declared after it has intercepted the event. The reason it works when elevation> 0 is because elevation is taken into account when sending a touch event, but if the elevations are equal, you will encounter the same problem.

+1
source

Source: https://habr.com/ru/post/1234854/


All Articles