Change TabWidget Indicator colour - android

I'm hoping someone can help. I am looking to change the indicator colour of my tab widget.
I had used the action bar tabs and had them styled correctly, however, I am using a nav drawer and require it to open over the tabs so I have changed to a tabhost/tabwidget.
I have followed this link:
Customizing tab indicator images in android?
Here is the strange part, I can change the tab colour, the divider colour, but when I try to change the tabStripLeft and the tabStrip right it won't work. I also tried to remove the strip below the indicator but that wouldn't work
android:background="#color/tab"
android:divider="#color/appPink"
android:tabStripLeft="#color/appPink"
android:tabStripRight="#color/appPink"
android:tabStripEnabled = "false"
I have tried drawables for the indicator too in case you may think this may be the problem. Does anyone have any ideas on this?
Here is how I've set them up in my activity:
private FragmentTabHost mTabHost;
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.container);
mTabHost.addTab(mTabHost.newTabSpec("home").setIndicator("Home"), PlaceholderFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("favourites").setIndicator("Settings"), settings_fragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("settings").setIndicator("Favourites"), mark_list_fragment.class, null);
If anyone has any thoughts I'd appreciate hearing them.

Related

How to add FragmentTabHost dynamically with icon set for each Tab, when my Activity class extends ActionBarActivity [duplicate]

I have implemented tabs using FragmentTabHost in support package, but the drawable icon is not shown?
How to show the drawable icon with FragmentTabHost?
mTabs = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabs.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabs.addTab(mTabs.newTabSpec("chapter").setIndicator("Chapter",getResources().
getDrawable(R.drawable.chapter1)), ContentFragment.class, null);
mTabs.addTab(mTabs.newTabSpec("section").setIndicator("section",getResources().
getDrawable(R.drawable.favourite1)), SectionFragment.class, null);
mTabs.addTab(mTabs.newTabSpec("video").setIndicator("Video",getResources().
getDrawable(R.drawable.video1)),VideoFragment.class, null);
mTabs.addTab(mTabs.newTabSpec("about").setIndicator("About",getResources().
getDrawable(R.drawable.about1)),AboutFragment.class, null);
I had the same problem. Apparently, setIndicator(label, icon) does not work correctly.
As a workaround, I used setIndicator(view) and created a simple custom view in tab_indicator.xml. For each tab, set the title and icon.

PagerSlidingTabStrip making horizontalscrollview's width fixed

I'm using PagerSlidingTabStrip library in my application now. I have 5 tabs, so it's over screen width. so I have to scroll to see last tab.
I want to see all tabs on the screen and never wanna scroll to see other items.
I tried changing HorizontalScrollView to LinearLayout in PagerSlidingTabStrip.java but it's weird a little. Indicator moved bad.
// public class PagerSlidingTabStrip extends HorizontalScrollView
public class PagerSlidingTabStrip extends LinearLayout
and also I tried shouldExpand options is true. but it didn't work again.
app:pstsShouldExpand="true"
What can i do for this ????
I had exactly same problem but following code ,I found that if you need to set tabs shouldExpand you need to do it before setting viewpager to tabs.
tabs = (PagerSlidingTabStrip) findViewById(R.id.slidingTabStrip);
//Before setting view pager
tabs.setShouldExpand(true); //Works
tabs.setViewPager(vpPager);
//After setting view pager
tabs.setShouldExpand(true); //Will not work
I solved this problem by myself. The problem is shouldExpand Attr doesn't work because our tabs are 5 so I can't. but when I set my tab count 4, it works and looks good. They filled with device screen width.
Anyway I changed this width size.
defaultTabLayoutParams = new LinearLayout.LayoutParams(dm.widthPixels/your tab count, LayoutParams.MATCH_PARENT);
I hope it will be helpful and save your time.

FragmentTabHost with drawable icon

I have implemented tabs using FragmentTabHost in support package, but the drawable icon is not shown?
How to show the drawable icon with FragmentTabHost?
mTabs = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabs.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabs.addTab(mTabs.newTabSpec("chapter").setIndicator("Chapter",getResources().
getDrawable(R.drawable.chapter1)), ContentFragment.class, null);
mTabs.addTab(mTabs.newTabSpec("section").setIndicator("section",getResources().
getDrawable(R.drawable.favourite1)), SectionFragment.class, null);
mTabs.addTab(mTabs.newTabSpec("video").setIndicator("Video",getResources().
getDrawable(R.drawable.video1)),VideoFragment.class, null);
mTabs.addTab(mTabs.newTabSpec("about").setIndicator("About",getResources().
getDrawable(R.drawable.about1)),AboutFragment.class, null);
I had the same problem. Apparently, setIndicator(label, icon) does not work correctly.
As a workaround, I used setIndicator(view) and created a simple custom view in tab_indicator.xml. For each tab, set the title and icon.

Add icon to tab in android

I am trying to add an icon to a tab in android and it isnt working.
here is part of my code, im not sure what is wrong
th = (TabHost) findViewById(R.id.thbodyview);
th.setup();
TabSpec specs = th.newTabSpec("tag1");
specs.setContent(R.id.Front);
specs.setIndicator("Front",getResources().getDrawable(R.drawable.tab_one));
th.addTab(specs);
When I run the app the tab just says "Front" and there is no icon, if someone could fix it that would be great.
Thanks
I know this question was asked over a year ago, but I shall provide an answer anyway, as it might be helpful to others wanting to know how this is possible.
The following code will enable you to retrieve the TextView and ImageView that form the title / heading of each tab (defined in the standard layout/tab_indicator.xml layout file):
TabHost tabHost = (TabHost) activity.findViewById(android.R.id.tabhost);
View currentTab = tabHost.getTabWidget().getChildAt(areaIndex);
or to get the view of the current tab that's in view:
View currentTab = tabHost.getCurrentTabView();
Then to actually get the Text and Image views:
TextView tabTitleField = (TextView) currentTab.findViewById(android.R.id.title);
ImageView tabTitleIcon = (ImageView) currentTab.findViewById(android.R.id.icon);
tabTitleIcon.setImageResource([specify your drawable resource here]);
Padding can be programmatically added to the ImageView using tabTitleIcon.setPadding(0, 0, 10, 0);
to add spacing between the title and the icon.

TabHost on Facebook for Android

Anyone know how facebook did this:
From what I know we cannot change the height of tabhost. I'm guessing that they laid the "Frank Cho" view over the tabhost to give it the appearance of being shorter but I may be wrong. Anyone know what's going on?
You actually can have custom looking tab widgets. You need to set the tab indicator to some custom layout (with your drawables) and you should be good to go.
Here's an semi-example:
final TabHost host = getTabHost();
final TextView indicator = (TextView) getLayoutInflater().inflate(
R.layout.tab_indicator,
getTabWidget(), false);
indicator.setText("Tab title");
host.addTab(host.newTabSpec("The tab tag")
.setIndicator(indicator)
.setContent([put your content here]));
}
Where the tab_indicator layout can look like this:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tab_label"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:textSize="14sp"
android:textStyle="bold"
android:minHeight="38dp"
android:background="#drawable/minitab" />
The minitab drawable is a drawable item selector (so you need to have an image for selected, default, pressed, and unselected). The facebook app used some white drawable image for the default tab and the blue gradient drawable for the unselected tabs.
Check out the Google IO Schedule app for a full working example: http://code.google.com/p/iosched/ (and specifically the TrackDetailActivity.java)
Somebody else had what I think is the correct answer, but deleted it for some reason...
The height in question is not that of the TabHost, but of the TabWidget.
Try using the version of setIndicator() that takes a View instead of just a String or String plus drawable resource. While I have not played with this yet, my understanding is that it solves this problem nicely.
Be careful, though, that you don't wind up with tabs that are too tough to tap.

Categories

Resources