4

The contextual action mode, when overlayed on top of an android.support.v7.widget.Toolbar, does not appear to filter touches over its entire width, but lets touches "fall through" to (invisible) widgets on the Toolbar.

My Toolbar contains a custom widget (one of the declared benefits of Toolbar). I have the contextual action mode styled to overlay the toolbar, and it hides it entirely. However, when I touch where the (now obscured) custom widget was located, the touch passes through to it. I wonder if this is a bug/oversight, but I may not have grasped this right, or my expectations may be lofty. I assume that the touch would not pass through if there was something on the contextual action overlay in the location of the obscured custom component.

I am testing this on Kitkat.

Here is some sample code:

MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.actionbar_toolbar);
    setSupportActionBar(toolbar);

    TextView barTextView = (TextView) toolbar.findViewById(R.id.textview_bar);
    barTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(MainActivity.this, "Bar TextView clicked", Toast.LENGTH_SHORT).show();
        }
    });

    mActionModeCallback = new ActionModeCallback();

    TextView mainTextView = (TextView) findViewById(R.id.textview_main);
    mainTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(MainActivity.this, "Main TextView clicked", Toast.LENGTH_SHORT).show();
            if (mActionMode != null) {
                return;
            }
            getSupportActionBar().startActionMode(mActionModeCallback);
        }
    });
}

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">
    <android.support.v7.widget.Toolbar
        android:id="@+id/actionbar_toolbar"
        android:layout_height="?attr/actionBarSize"
        android:layout_width="match_parent"
        android:background="?attr/colorPrimary"
        app:theme="@style/ThemeOverlay.AppCompat.ActionBar">
        <TextView
            android:id="@+id/textview_bar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Bar"
            android:textColor="#FF0000"/>
    </android.support.v7.widget.Toolbar>
    <TextView
        android:id="@+id/textview_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="SomeTextToClick"/>
</LinearLayout>

styles.xml

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="windowActionModeOverlay">true</item>
    </style>
</resources>

I also tried setting up the action mode with the following alternative, but the behavior was the same:

Toolbar toolbar = (Toolbar) MainActivity.this.findViewById(R.id.actionbar_toolbar);
mActionMode = toolbar.startActionMode(mActionModeCallback);

At this point I can only think of either explicitly disabling the custom component whenever the contextual action mode comes on, or somehow filling the contextual action bar with invisible junk to more seriously obscure the toolbar.

Some screenshots below.

Before clicking anything:

No contextual action mode before clicking

After clicking "SomeTextToClick" - contextual action mode is now on, and the text in the toolbar is obscured, but at this point I can click in the center of the contextual action bar, and the click gets handled by the listener on the "Bar" TextView in the toolbar:

Contextual action mode enabled after clicking "SomeTextToClick"

Can anyone help ?

amdixon
  • 3,814
  • 8
  • 25
  • 34
Uli
  • 2,828
  • 20
  • 23
  • A similar question was asked not too long ago looking specifically for a workaround: http://stackoverflow.com/questions/29319986/how-do-i-disable-sliding-tabs-when-in-contextual-action-bar-by-making-the-tabs Should a workaround be needed, though? – Uli Apr 18 '15 at 07:40

0 Answers0