TabHost Tab page of Android Control

Source: Internet
Author: User

TabHost is used to display the Tab page.

 

Source code download

I. Overview

Provides the window view container of the Tab page. It has two children. One group is the label of the Tab page that you can select and the other group is FrameLayout, which is used to display the content of the Tab page. Some elements usually control the use of this container object, rather than the value set in the child element itself.

Ii. Important Methods

AddTab (TabHost. TabSpec tabSpec): Add a Tab

ClearAllTabs (): clears all associated tabs.

GetCurrentTab (): returns the current Tab page.

GetTabContentView (): returns the FrameLayout containing the content.

NewTabSpec (String tag): returns a new TabSpec associated with it.

Iii. Instances

1. layout file, use FrameLayout

<? Xml version = "1.0" encoding = "UTF-8"?>
<FrameLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">

<TextView android: id = "@ + id/view1"
Android: background = "@ drawable/B"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: text = "Page 1"/>

<TextView android: id = "@ + id/view2"
Android: background = "@ drawable/c"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: text = "Page 2"/>

<TextView android: id = "@ + id/view3"
Android: background = "@ drawable/d"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: text = "Page 3"/>

</FrameLayout>

2. inherit TabActivity

Public class TabHostDemo extends TabActivity

3. Obtain this abHost

TabHost tabHost = getTabHost ();

4. Set Layout

LayoutInflater. from (this). inflate (R. layout. tabhostpage, tabHost. getTabContentView (), true );

5. Add a Tab

TabHost. addTab (tabHost. newTabSpec ("tab1 ")
. SetIndicator ("tab1 ")
. SetContent (R. id. view1 ));
TabHost. addTab (tabHost. newTabSpec ("tab3 ")
. SetIndicator ("tab2 ")
. SetContent (R. id. view2 ));
TabHost. addTab (tabHost. newTabSpec ("tab3 ")
. SetIndicator ("tab3 ")
. SetContent (R. id. view3 ));

 

    

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.