The above is final.
The code structure is as follows.
Main. XML code:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <! -- The layout file defines the content of the label. The layout file must use framelayout as the root element --> <br/> <framelayout xmlns: android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <br/> <! -- Content of the first tag --> <br/> <linearlayout Android: Id = "@ + ID/widget_layout_blue" <br/> Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" <br/> Android: Orientation = "vertical"> <br/> <edittext Android: Id = "@ + ID/widget34" Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" Android: text = "edittext" <br/> Android: textsize = "18sp"> <br/> </edittext> <br/> <button Android: Id = "@ + ID/widget30 "Android: layout_width =" wrap_content "<br/> Android: layout_height =" wrap_content "Android: TEXT = "button"> <br/> </button> <br/> </linearlayout> <br/> <! -- The second TAG content analogclock is the clock component --> <br/> <linearlayout Android: Id = "@ + ID/widget_layout_red" <br/> Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" <br/> Android: Orientation = "vertical"> <br/> <analogclock Android: id = "@ + ID/widget36" <br/> Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"> <br/> </analogclock> <br/> </linearlayout> <br/> <! -- The third TAG content, radiobutton, must be in radiogroup. --> <br/> <linearlayout Android: Id = "@ + ID/widget_layout_green" <br/> Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" <br/> Android: Orientation = "vertical"> <br/> <radiogroup Android: id = "@ + ID/widget43" <br/> Android: layout_width = "166px" Android: layout_height = "98px" <br/> Android: orientation = "vertical"> <br/> <radiobutton Android: Id = "@ + ID/widget44" <br/> Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" <br/> Android: text = "radiobutton"> <br/> </radiobutton> <br/> <radiobutton Android: id = "@ + ID/widget45" <br/> Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" <br/> Android: TEXT = "radiobutton"> <br/> </radiobutton> <br/> </radiogroup> <br/> </linearlayout> <br/> </framelayout> <br />
Taghosttest. Java code:
Package cn.com. taghost. test; </P> <p> Import android. app. tabactivity; <br/> Import android. graphics. color; <br/> Import android. OS. bundle; <br/> Import android. view. layoutinflater; <br/> Import android. view. viewgroup; <br/> Import android. widget. tabhost; </P> <p> public class taghosttest extends tabactivity {</P> <p> private tabhost mytabhost; </P> <p> @ override <br/> protected void oncreate (bundle savedinstancesta Te) {<br/> super. oncreate (savedinstancestate); <br/> mytabhost = This. gettabhost (); </P> <p>/** <br/> * inflate (INT resource, viewgroup root, Boolean attachtoroot) <br/> * resource is obviously a resource index id <br/> * When attachtoroot is true, root represents a component that can be placed in a container <br/> * When attachtoroot is set to false, root only represents an object with a stored value <br/> * This method means, according to R. layout. the tag view generated by main is added to mytabhost. <br/> * inflate method of the layoutinflater class in the parent container obtained by gettabcontentview () There are the following fragments <br/> * If (root! = NULL & attachtoroot) {<br/> root. addview (temp, Params ); <br/>}< br/> temp is a tag-related view generated based on the resource specified by the resource. <br/> */<br/> layoutinflater. from (this ). inflate (R. layout. main, <br/> mytabhost. gettabcontentview (), true); <br/> mytabhost. setbackgroundcolor (color. argb (150, 22, 70,150); </P> <p> mytabhost. addtab (mytabhost. newtabspec ("one") <br/>. setindicator (""). setcontent (R. id. widget_layout_blue); </P> <p> mytabhost. addtab (mytabhost. newtabspec ("two") <br/>. setindicator ("B", getresources (). getdrawable (R. drawable. icon) <br/>. setcontent (R. id. widget_layout_green); </P> <p> mytabhost. addtab (mytabhost. newtabspec ("three") <br/>. setindicator ("C", getresources (). getdrawable (R. drawable. icon) <br/>. setcontent (R. id. widget_layout_red); <br/>}< br/>}
This method is easy to implement. Let's see what we have done.
Step 1: Define the layout file of the label content. The layout file must use framelayout as the root node.
Step 2: Let the activity inherit tabactivity and implement its own code.