material-components / material-components/material-components-android

[TabLayout] Margin for each tab item

Open
#1,507 6 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request Widget: Tab
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:
![image](https://user-images.githubusercontent.com/76348/88342475-15a6b980-cd05-11ea-8714-6b0583bdff30.png)

But since this is not possible from the styles it will appear like this since:
![image](https://user-images.githubusercontent.com/76348/88342494-1f302180-cd05-11ea-99b2-81a36edd9cf0.png)

# 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.