Questions tagged [android-tablayout]

Android TabLayout provides a layout to organize pages of information.

TabLayout provides a horizontal layout to display tabs.

Population of the tabs to display is done through TabLayout.Tab instances. You create tabs via newTab(). From there you can change the tab's label or icon via setText(int) and setIcon(int) respectively. To display the tab, you need to add it to the layout via one of the addTab(Tab) methods.

Useful links

2044 questions
47
votes
13 answers

TabLayout set spacing or margin each tab

I want to set margin in between each tab. Like in PagerTabStrip which has setTextSpacing(int textSpacing) to make text spacing between tab. Can TabLayout do that?
45
votes
16 answers

Android Tab layout: Wrap tab indicator width with respect to tab title

Is there any way to wrap tab indicator width with respect to tab title ?
Narayan C.R
  • 866
  • 1
  • 8
  • 22
44
votes
8 answers

Tab change listener android

My HomeActivity extends AppCompatActivity that uses 2 tabs. public class HomeActivity extends AppCompatActivity { private SectionsPagerAdapter mSectionsPagerAdapter; private TabLayout tabLayout; ... @Override protected void…
jay
  • 1,982
  • 2
  • 24
  • 54
43
votes
5 answers

Dynamically add and remove tabs in TabLayout(material design) android

I have a TabLayout and inside that I have ViewPager. I need to dynamically add and remove tab in tablayout(material design). I can able to add the tabs dynamically but while removing the tab, tab is removing correctly. But viewpager last item is…
40
votes
9 answers

Cannot remove Padding from Tabs when using Custom views with Tab Layout

I have added a Relative Layout in Custom View and have added this in Tab Layout. I am using a white background for tabs and have not applied any padding in tabs custom layout. But then also I am getting padding on tabs due to which I am shown some…
ajay
  • 886
  • 2
  • 12
  • 27
40
votes
5 answers

How to get current selected tab index in TabLayout?

When I use ActionBar tabs, I use this code. private int getCurrentTabIndex() { ActionBar actionBar = activity.getSupportActionBar(); ActionBar.Tab selectedTab = actionBar.getSelectedTab(); if(selectedTab == null){ return 0; …
Semyon Tikhonenko
  • 3,872
  • 6
  • 36
  • 61
39
votes
9 answers

TabLayout with viewpager not smooth scrolling

Edit I have followed these tutorials to fix this…
36
votes
3 answers

How is TabItem used when placed in the layout XML?

The TabLayout documentation gives an example of nesting TabItem directly inside TabLayout like so:
Nathan Fig
  • 14,970
  • 9
  • 43
  • 57
33
votes
2 answers

How to set Tab width in Tab layout?

I'm trying to create a tab layout which has two tabs. When I run the app on small mobile the tab layout looks fine but when I run the same application on Tablet it shows like this. It looks like this on Tablet: I want each tab to occupy entire…
user5912784
33
votes
4 answers

Changing the background color of a Tab in TabLayout (Android design support library) doesn't occupy the entire tab space

I have a TabLayout (design support library) which is tied up to a ViewPager containing three tabs. I have designed a custom layout and set that to each tab in the TabLayout. I have been trying to change the background color of the currently…
Itapu Vinay
  • 687
  • 2
  • 9
  • 18
32
votes
4 answers

Changing TabLayout icons on left, top, right or bottom in com.android.support:design:23.1.0

I'm pretty new to android development. So bear with me. I've been trying to align the icon and text in same line in com.android.support:design:23.1.0 for a day. Apparently in com.android.support:design:23.1.0 they've changed the default icon…
32
votes
7 answers

How to set android TabLayout in the bottom of the screen?

My question is how I can set the new android material design TabLayout to be in the bottom of the screen, kind of like Instagram's bottom toolbar. If you have never seen Instagram's UI here is a screenshot of it : . If there is a better way of…
JorgeC
  • 615
  • 3
  • 7
  • 13
31
votes
6 answers

Remove the selector line under current Tab for a TabLayout

I am using a TabLayout with 3 tabs. I customized the view of my tabs and therefor, I need to remove the following line under my tabs ( the screenshot doesnt come from my app): I am NOT using a TabHost or a TabWidget and therefor, I cannot use…
Virthuss
  • 3,142
  • 1
  • 21
  • 39
30
votes
4 answers

Add Icons+Text to TabLayout

I am working on a screen which contains Three tabs I am trying to add an icon with My text in tabs and i want the image to be upper the text and there should be some space between them it is my code. public class HomeScreen extends…
28
votes
13 answers

How to scroll tablayout programmatically - Android

I have created 30 scrollable tabs using tablayout. So first three tabs are visible on screen and rest of them are invisible which can be scroll using swipe gesture. The problem is when I am selecting last tab programmatically but it is not get…