Enable scrolling of tags in Android tabhost

Source: Internet
Author: User

Http://www.cnblogs.com/shirley-1019/archive/2013/04/10/3012824.html

Very nice piece of code:

public class Tabhosttestactivity extends tabactivity implements
tabcontentfactory {
private string[] lables = new string[] {"Home", "message", "friend", "more"};
Private int[] icons = new int[] {r.drawable.ic_home, r.drawable.ic_msg, R.drawable.ic_friend, r.drawable.ic_more};

/** called when the activity is first created. */
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.tabhost);
Tabhost th = Gettabhost ();
Tabhost = Gettabhost ();
for (int i = 0; i < lables.length; i++) {
View view = Layoutinflater.from (this). Inflate (R.layout.menu, NULL);
ImageView Menu_ic = (ImageView) View.findviewbyid (r.id.menu_ic);
Menu_ic.Setimageresource(Icons[i]);
TextView Text = (TextView) View.findviewbyid (r.id.menu_lable);
Text.SetText(Lables[i]);
Tabhost.addtab (Tabhost.newtabspec (string.valueof (i)). Setindicator (view). SetContent (this));
}
Tabhost.setcurrenttab (0); }

@Override
public void ontabchanged (String tabId) {
TabId is the string passed in Newtabspec (string tag) tag, where tag is 0,1,2,3 can be converted to plastic for easy judgment
int TabID = integer.valueof (TabID);
for (int i = 0; i < Mtabwidget.getchildcount (); i++) {
if (i = = TabID) {
Mtabwidget.getchildat (i). Setbackgroundresource (
R.drawable.indicator_selected);
} else {
Mtabwidget.getchildat (i). Setbackgroundresource (
R.drawable.indicator_unselected);
}
}
}

Tabhost switching activity by gesture

Http://www.eoeandroid.com/thread-238527-1-1.html's a blast.

Enable scrolling of tags in Android tabhost

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.