Different background for each actionbar tab - android

In my app I've got three tabs in an actionbar (using ActionBarSherlock). In an xml
style I set/overwrite default background selector and everything works well. But... now I've got to set individual backgrounds for each tab. Visually I want to have my tabs with different underline color.
Ideally I'd like to have something like this:
Tab t = actionBar.newTab();
t.setBackground(...);
actionBar.addTab(t);
But there is no method setBackground.
So, I created a custom view for the tabs and now I have this:
The first problem is the size. I'd like to have exactly the same size I had with standard/default tabs.
The second problem is the background selector doesn't work. When I press a not selected tab it doesn't change its state/background, and it is the same selector that works perfectly with TabView.background.
What I'd like to have exactly is standard actionbar tabs with different background selector for each tab. Any ideas?

Related

How to make the title bar change color when the tab is changed

If I am on a tab in a tabbed activity, and I change tabs, how do I make the title bar and tab indicator change colors? An example of what I'm talking about can be seen below (done on paint).
App bar changing color when different tabs are selected
I figure that manipulating the different elements and what color resources that they use could be done to change everything uniformly, but at the same time, I don't know how to do that. I have four tabs, and four sets of colors picked from the material design library, red, blue, green and yellow. Including red dark, blue dark, etc.
I'm not using the default tab layout activity that comes with android studio, instead, I am using one similar to the one used here
https://androidbelieve.com/navigation-drawer-with-swipe-tabs-using-design-support-library/
minus the navigation drawer. All help would be sincerely appreciated, though I'm afraid that I'm still quite a beginner so I would appreciate it if you could make it as simple as possible.
:D
You can just right code according to selected tab position
for tab 1
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F00")));
for tab 2
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FF0")));
for tab 3
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F0F")));
I use
getWindow().setStatusBarColor(color);
for change color title bar.

How to set the background color of an Android tab?

I have a view pager and have tabs at the very top. Each tab has an icon. I am not using textviews for the tabs. I've tried searching for a way to change the background color of the tabs, but all I get is solutions involving use a textview for the tabs.
Is there a way to set the background color of the tabs without using a textview? I have set icons to the tabs.
Note: The tabs will all be the same color.
This will be Awesome for you ,you can customize everything,set an icon or text or both ,change Background color and Everything
https://github.com/astuetz/PagerSlidingTabStrip

SlidingTabStrip indicator underneath SlidingTabLayout

I am using a fragment pager adapter for two tabs, based almost identically on the code from the Sliding Tabs Basic sdk sample. All was working fine until I tried to swap out the action bar for the tool bar. I had to switch up my theme to light, and now I've noticed that the tabs were using a transparent default colour. I want my tabs to be the same colour as the tool bar, but in setting the colour, they are obscuring the sliding tab strip indicator completely. What is the correct way to push the SlidingTabStrip to the front?
I've tried setting the background resource of the tab programmatically rather than via the selectableItemBackground theme property. The background still obscures the indicators.
I've tried to bringToFront() or bringChildToFront() the SlidingTabStrip in multiple places, (it is created in the constructor of the SlidingTabLayout). I've tried it after the for loop in SlidingTabLayout.populateTabStrip() which seems sensible as this is where the tab views are created.
I wonder why no-one else has had this issue ?!
Well I figured out the solution and it actually took me far too long - by inverting the problem we can leave the selectableItemBackground transparent when unpressed, and set:
<item name="android:windowBackground">#color/my_bg_color</item>
in the theme itself. This means I can have my tabs the same colour as the tool bar and not obscure the indicator. It's a weird set-up though, because if I did want the tabs a different colour to the windowBackground or tool bar, with the indicator un-obscured, this would not be the solution!

Selected tab background color (ActionBarSherlock)

I have three tabs (ActionBarSherlock) and by default there is a small indicator which is blue. What I want is to change so that the selected tab is red, i.e. not only the indicator but the whole tab.
Is that possible? I have tried some suggested solutions without luck.

How do I set the color for a tabview in android?

I want to change the colour of a tabview from the default grey (and black when not selected) to red and green when not selected.
In the tab Widget class I'm trying to set the colour using these functions
tabHost.setBackgroundColor(Color.RED);
tabHost.getTabWidget().setBackgroundColor(Color.GREEN);
But they don't work, its still the default colour. How do I manually set the background and tab colours of a tab widget in android? Also, is it possible to do it in xml?
See Step 4. at this blog, it's how I have done it, very simple, easy to change and tweak if you need to and it's all in XML.
Custom tabs in android tabhost

Categories

Resources