material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[TabLayout] Can't customize TabView click listener

Open vvinogra opened this issue 11 months ago • 0 comments

Description:

I have a business logic in the app to perform a certain validation when the TabView is clicked. Due to the current TabLayout implementation, I can't prevent tab selection when the tab is clicked.

Expected behavior:

We should have an option to control this behavior.

Source code: TabLayout.java

    @Override
    public boolean performClick() {
      final boolean handled = super.performClick();

      if (tab != null) {
        if (!handled) {
          playSoundEffect(SoundEffectConstants.CLICK);
        }
        tab.select();
        return true;
      } else {
        return handled;
      }
    }

Minimal sample app repro:

  1. Create Activity/Fragment with TabLayout and a few TabView items.
  2. Click on the tab

Material Library version: 1.11.0

vvinogra avatar Mar 17 '24 09:03 vvinogra