Android Study Notes (30): tab TabHost Analysis

Source: Internet
Author: User

Android Study Notes (30): tab TabHost Analysis

The TabHost component is a container that can store multiple tabs on the interface. The tab size is the same as that of the external container.

The TabWidget component is the title bar of TabHost. You can click the tab to switch.

The TabSpec component is a Tab ).

 

Use TabHost as follows:

1. Define a TabHost component in the XML file and define a FrameLayout. Add content to it.

2. The Activity should inherit from TabActivity.

3. Call the getTabHost () method of TabActivity to obtain the TabHost object.

4. Create and add tabs using the TabHost object method:

NewTabSpec (Stringtag): Create a tab

AddTab (TabHost. TabSpectabSpec): Add a tab

 

In the layout file, several controls must reference the existing Android system IDs and cannot be defined by themselves:

TabHost: @ android: id/tabhost

TabWidget: @ android: id/tabs

FrameLayout: @ android: id/tabcontent

 

When the tab of TabHost changes, you can use OnTabChangeListener to bind event listening to it.

TabSpec can use the setContent (intviewId) and setContent (Intentintent) Methods to set the tab content, that is, TabSpec can directly reprint another Activity.

 

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.