0
I own a TabLayout
in which I programmatically create tabs in this method:
mTabLayout.removeAllTabs();
for(int i = 0; i < list(); i++) {
mTabLayout.addTab(mTabLayout.newTab().setText(list(i).name), false);
}
TabLayout.Tab newPlanTab = mTabLayout.newTab().setText(R.string.new_plan_tab);
mTabLayout.addTab(newPlanTab, false);
In this last tab that I add, I want to set a background and color of different text to highlight it, but I am not able to access these properties. How can I do that?
EDIT
One solution I found was to use a CustomView
, but I’m not sure how to customize this CustomView
to be like the others only with the different BG, she must inherit from whom?
Is Tablayout, by any chance, working in conjunction with a Viewpager? If yes, there is a very easy way to do it, even you won’t even need to be creating/removing tabs on your own.
– Márcio Oliveira
Nao @Márciooliveira , when a tab is selected there is a request to download information that is modified in the same tab, simply changing the data shown on the screen.
– leofontes
Yet you could use Viewpager to load different data in the same Fragment (only in different instances). I’m saying this because Viewpager + Tablayout is almost like one thing, rs, so there are native methods to update Tablayout to certain Viewpager features. Ex: tab name, number of tabs, etc. For example, Chrome implements a Viewpager and adds tabs dynamically.
– Márcio Oliveira
I understand what you’re saying, but what I want is to change the background of just one tab. The implementation of the rest I’ve done and is working, this would just be the icing on the cake.
– leofontes
You want to set a different highlight than is already created in the style of Tablayout?
– Márcio Oliveira
Yes @Márciooliveira, because it will be a tab to create a new tab. I talked to a colleague who is Senior in the area and the only solution he remembered was to use customView even, but wanted to get away from it if possible.
– leofontes
That’s what I was going to comment on. Natively I don’t think I can.
– Márcio Oliveira
Try creating a theme for this custom view with "Textappearance.Design.Tab" or "Widget.Design.Tablayout" as the parent and put a background attribute.
– Márcio Oliveira