Three ways to add tabs to the "Android Essentials" Tabhost navigation bar

Source: Internet
Author: User

The navigation bar implemented using Tabhost has three ways to add pages, which are added directly to the tab of the layout code, added by the include tag, and specified by the Java code for another activity addition. Here are some examples of three methods:

Add tabs directly to the tab of the layout code

With the drag control dragged out of the tabhost, at its layout level there will be three linearlayout,id, respectively, TAB1, TAB2, TAB3, as shown in:

Then we can create a new layout, in this layout design the interface, the XML code directly into the tab (1, 2, 3) of the label, as shown, the design of the text tag into the TAB1 this label:

This method is relatively simple, easy to understand, but this method is only suitable for small application interface, if the application interface is very complex, this layout file will become very large, not conducive to the maintenance of code.

Use the include tag instead of layout

The include tag can be loaded with a layout file embedded in another layout file, which is very useful for slicing large layout files, which is a blog post on the use of include tags, http://blog.csdn.net/zgljl2012/ article/details/44665643
Here, this method should be better understood, is to design a layout file, and then use the include tag to embed it in a tag. We will not dwell on it here.

Add a tab using the AddTab (Tabspec Tabspec) method

Mtabhost is the Tabhost control, and then uses Newtabspec to create a tabspec, and sets the name "Page Three" and set its contents to be Tab3 this activity:

mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("页面三")                .setContent(new Intent(this,Tab3.class)));

The above three methods suggest the use of the second and third, the second is suitable for static tab display, the third is suitable for the user to interact with the tab page.

Three ways to add tabs to the "Android Essentials" Tabhost navigation bar

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.