material-components / material-components/material-components-android
[TabLayout] ViewPager integration isn't effective
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
The current implementation of TabLayout inside ViewPager is bad... I tried using just icons in the TabItems (in XML) for an app and when my adapter gets assigned in the activity/fragment the tab layout immediately disposes all the icons and shows blank tabs (it internally tries to set the view pager titles but since none exist in the adapter it nulls them out to empty strings).
Ideally, this should not happen and the tabs should not be re-created programmatically to texts but rather it should reinflate the tab layout with the tab icons specified in the XML over PagerAdapter's implementation.
Alternatively, at least the developer should be allowed to specify whether to take the pager adapter's titles as tabs with a starting method call--something like setting a boolean property shouldTabLayoutUseViewPagerTitles to false should do the trick.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with TabLayout.java at lines 1473-1479 and trace what happens when a ViewPager adapter is assigned. Reproduce the icon-only XML tab case with an adapter that provides no titles, then determine whether the existing tabs or an opt-out for pager titles should be preserved. Done means the intended tab icons remain visible without breaking normal ViewPager title integration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100