[Android Basics] Three Ways to add a tab in the TabHost navigation bar: androidtabhost
There are three ways to add pages in the navigation bar implemented by using TabHost: adding pages directly in the tab of the layout Code, adding pages using the include tag, and adding pages using the Java code to specify another Activity. The following is an example of three methods:
Directly add a tab in the tab of the layout code
The TabHost dragged out by the Drag Control has three LinearLayout layout IDs at the layout level: tab1, tab2, and tab3, as shown in:
Then we can create a new Layout. After designing the interface in this Layout, we can directly add the xml code to the tab (1, 2, 3) label, as shown in, put the designed text label in the tab1 label:
This method is relatively simple and easy to understand, but it is only suitable for small application interfaces. If the application interface is very complex, the layout file will become very large, which is not conducive to code maintenance.
Use the include label instead of layout
Include labels can load a layout file, embedded in another layout file, very helpful to split large layout files, this is my article on the use of include labels blog, http://blog.csdn.net/zgljl2012/article/details/44665643
At this point, this method should be better understood, that is, first design a layout file, and then use the include tag to embed it into a tag. I will not go into details here.
Use the addTab (TabSpec tabSpec) method to add a tab
MTabHost is the TabHost control. Then, newTabSpec is used to create a TabSpec and the name is "Page 3". The Activity is Tab3:
MTabHost. addTab (mTabHost. newTabSpec ("tab3"). setIndicator ("Page 3"). setContent (new Intent (this, Tab3.class )));
We recommend that you use the second and third methods, the second method for static tab display, and the third method for tabs that need to interact with users.