FragmentTabHost with drawable icon - android

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.

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.

Change TabWidget Indicator colour

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.

How top set tab icon and label in FragmentTabHost

I am using FragmentTabHost to implement bottom tabs with icon and label but following sentence shows only label
mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple",getResources().getDrawable(R.drawable.ic_launcher)),
Fragment1.class, b);
I also see somewhere following works properly
setIndicator(View);
but I don't know syntax to set custom view in setIndicator
plz help
Thanks...
I make custom view and set it as setIndicator(View v);
View chatView=LayoutInflater.from(this).inflate(R.layout.chat_icon,null);
mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator(chatView),
Fragment1.class, b);

use android backAsUp with custom title bar

I have a custom title bar, a simple relative layout, that I set as the custom title bar of my activity. But at want the android BackAsUp icon < to show up as usual (i.e. to the left of my custom layout). How do I do that? here is my code so far.
this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);
LayoutInflater inflator = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.my_title_bar, null);
this.getActionBar().setCustomView(v);
Update:
I have tried the answer at Remove Icon but have HomeAsUp in ActionBar they don't work. So one question, is order of setting those flags matter?
Adding the following combo solved the problem.
getActionBar().setIcon(
new ColorDrawable(getResources().getColor(android.R.color.transparent)));
this.getActionBar().setDisplayShowHomeEnabled(true);

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.

Categories

Resources