How do I change the color of the bottom bar for TabWidget? I have successfully changed the tab background color but the bottom bar is still grey/orange and I couldn't find any info in the Android doc and source regarding this. Thanks.
See:
to enable/disable this line:
tabHost.getTabWidget().setStripEnabled(boolean);
to set drawable at left for this line:
tabHost.getTabWidget().setLeftStripDrawable(drawable);
to set resourse at left for this line
tabHost.getTabWidget().setLeftStripDrawable(resId);
to set drawable at right for this line:
tabHost.getTabWidget().setRightStripDrawable(drawable);
to set resourse at right for this line:
tabHost.getTabWidget().setRightStripDrawable(resId);
I'm guessing that "bottom bar" refers to the optional horizontal line that separates the tabs and the content. Take a look at the various tabStrip attributes described in the TabWidget API doc. You can set different drawables for the left and right parts of the strip.
public void setTabColor(TabHost tabhost) {
int totalTabs = tabhost.getTabWidget().getChildCount();
for(int i=0;i<totalTabs;i++) {
if(tabHost.getTabWidget().getChildAt(i).isSelected()){
tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_selector); //selector xml for selected
tabHost.getTabWidget().setStripEnabled(true);
tabHost.getTabWidget().setRightStripDrawable(R.drawable.tab_strip_thin);
tabHost.getTabWidget().setLeftStripDrawable(R.drawable.tab_strip_thin);
}
}
}
Related
My question is more or less similar to this question, but the response approved as the answer for the same doesn't solve my issue.
I'm implementing tab structures using the FragmentTabHost class. When the tab background color is not explicitly specified, the tab indicator line seems to appear as Android provides. But when I programatically change the tab's background color, the tab indicators disappear (hidden).
Currently, I assign the tab background color this way :
private void customizeTabbs() {
for (int i = 0; i < mTabHost.getTabWidget().getTabCount(); i++) {
View tabChild= mTabHost.getTabWidget().getChildAt(i);
..
..
tabChild.setBackgroundResource(someColorResource);
}
}
I also tried to change the background color in the XML way by adding to styles.xml , following this as:
<item name="tabBackground">#color/someColor</item>
<item name="tabIndicatorColor">?#color/someOtherColor</item>
The solution suggested for one similar question also did not help me.
How do you set the color of the tab host indicator color I want to change the light blue default color to lets says RED.
And I need to this programatically as I am making the tabs programatically.
I did some research and looked at this example but it does not work for me. With the progamtic approach.
TabWidget current tab bottom line color
Thanks
You can do this programmatically, even change the color as you want, by following the solution in the linked question you mention, plus adding a ColorFilter to adjust the color.
So:
Create the appropriate drawable. The easiest way, as mentioned in one of the answers, is using https://jgilfelt.github.io/android-actionbarstylegenerator/
Place into your project the tab_indicator_ab_example.xml (in drawable) plus the 6 associated png files (tab_*.png) for each drawable density.
After creating the tabs, use the code that iterates over the TabWidget child views to set their background, however:
Instead of setting the drawable as-is, use a color filter to change its color to the desired one.
Instead of this code:
for(int i = 0; i < widget.getChildCount(); i++) {
... /* same as before */
v.setBackgroundResource(R.drawable.your_tab_selector_drawable);
}
write something like this:
for(int i = 0; i < widget.getChildCount(); i++) {
... /* same as before */
Drawable d = getResources().getDrawable(R.drawable.tab_indicator_ab_example);
d.setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN);
v.setBackgroundDrawable(d);
}
I have an action bar with 4 tab entries, like in this image:
I just used the theme Holo-Dark.
I like to have color-blocks/undeline that marks the selected item in a different color.
So when the user selects "Green" the color of the selection indicator is also green and not the standard blue.
(Not the tab background, it is good in black)
How can I achieve this?
I currently added the items with this code in the onCreate method of the Activity:
for (int i = 0; i < myModel.getTabCount(); i++) {
actionBar.addTab(
actionBar.newTab()
.setText(myModel.getPageTitle(this, i))
.setTabListener(this)
);
}
I looked up the documentation for class Actionbar.Tab and found nothing useful there.
DevByte did a great tutorial on this:
http://www.youtube.com/watch?v=tRg_eDfQ8fk
There is also a link in the description to sample code
You need to set different background drawables for the different tabs. You can make a Nine-Patch drawable in each color that mimics the thick underline of the tab. In your code, for each tab you will have to
Inflate a custom view
call setBackgroundResource() on that view
Create a Tab and call setCustomView() on it
You can do this by setting custom view at the time of creation of the tab.It would be something like
final Tab firstTab = actionBar.newTab()
.setText(mAppSectionsPagerAdapter.getPageTitle(0))
.setCustomView(R.id.custom_tab_view_red);
final Tab secondTab = actionBar.newTab()
.setText(mAppSectionsPagerAdapter.getPageTitle(1))
.setCustomView(R.id.custom_tab_view_blue);
// etc
Check this question..It has some useful information for you
I have a TabWidget and I'm trying to style the divider. (See image above)
I set the Divider Drawable of the TabWidget but the top & bottom part is unchanged. I can't figure out how to style it.
All you need to do is set the dividerPadding attribute to 0dp in your TabWidget.
android:dividerPadding="0dp"
Also, maybe consider switching to ActionBar.Tabs instead, just considering TabWidget is deprecated.
It seems that Holo theme has default 16 pixels dividerPadding for each TabWidget.
I try to set it to zero in the XML but it is not working.
Fortunately, it works for me to set it dynamically as below
myTabHost.getTabWidget().setDividerPadding(0);
Note: I am using android.support.v4.app.FragmentTabHost
are you talking about grey bars on the top and the bottom of the divider? use fill_parent for the drawable's height and width if that is the case!
I need xml styles for tab on or off state,whenever i click the button,display rounded rectangle on button.How can i make new style for given image.please give some tips for me
how to create styles for rounded rectangle like this image
For that add rounded cornered images as a background to tab:
tab = tabs.newTabSpec("tab_Busquedas");
tab.setContent(new Intent().setClassName("com.grapp", "com.grapp.homes").putExtras(bundle));
tab.setIndicator(null,null);
tabs.addTab(tab);
//here you set the image with rounded corners over the tab.
tabs.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.mytab_roundedcorners);
This solution is posted at: How to achieve rounded tabs in Android 2.1 +
You can make use of the themes feature for the same.
http://developer.android.com/guide/topics/ui/themes.html
If you make use of this feature, maintainability will also be easy.
Regards,
SSuman185