material-components / material-components/material-components-android
[TabLayout] Margin for each tab item
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Currenlty you can not change a Tab item from the TabLayout from the styles, you have to do some hacky thing like:
The issue is when you want to change the tab background shape into something like:

But since this is not possible from the styles it will appear like this since:

# Possible Solution
One atribute `tab_margin_start` and each margin for each item maybe?
# Current hacky solution
Hacky programaticaly solution [source](https://spotandroid.com/2016/11/02/how-to-add-margins-between-tabs-in-tablayout/):
```kotlin
for(int i=0; i < mTabLayout.getTabCount(); i++) {
View tab = ((ViewGroup) mTabLayout.getChildAt(0)).getChildAt(i);
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) tab.getLayoutParams();
p.setMargins(0, 0, 50, 0);
tab.requestLayout();
}
```
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 by reading the TabLayout implementation and its tab item layout handling. Compare the requested per-item margins with the current styling behavior and the documented programmatic workaround. Done means margins can be configured through supported styling or attributes without that workaround, with behavior verified for multiple tabs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100