The approach is to fragment+fragmenttabhost components to achieve this common app home page effect
First give the Main.xml file
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "android:orientation=" vertical "android:layout_width=" match_parent "android:layout_height=" Match_parent " > <framelayout android:id= "@+id/realtabcontent" android:layout_width= "Fill_parent" android:layout_height= "0dip" android:layout_weight= "1" android:background= "@color/white"/> <linearlayout android:layout_wi Dth= "Match_parent" android:layout_height= "wrap_content" android:layout_gravity= "bottom" android:orientation= "vert" ical "> <view android:layout_width=" match_parent "android:layout_height=" 1px "android:background=" @c Olor/color_home_tab_line "/> <android.support.v4.app.fragmenttabhost android:id=" @android: Id/tabhost "and Roid:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:background= "@color/et_divider_ Disable "> <framelayout andRoid:id= "@android: Id/tabcontent" android:layout_width= "0DP" android:layout_height= "0DP" Android:layout_weigh
t= "0"/> </android.support.v4.app.FragmentTabHost> </LinearLayout> </LinearLayout>
main code:
public class Mainactivity {@ViewInject (Android).
R.id.tabhost) Private Fragmenttabhost mtabhost;
Private Layoutinflater Layoutinflater; private int mimageviewarray[] = {R.DRAWABLE.HOME_TAB1, r.drawable.home_tab2, R.DRAWABLE.HOME_TAB3, R.drawable.home_
TAB4};
Private String mtextviewarray[] = {"Home page", "Circle", "Information", "Personal Center"};
Private Class fragmentarray[] = {fragment1.class, fragment2.class, fragment3.class,fragment4.class};
protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Init ();} @Override protected void init () {//List=new jsonarray ();
Layoutinflater=layoutinflater.from (this); Inittabhost ()//Initialize Bottom menu}/** * Initialize bottom toolbar * * private void Inittabhost () {mtabhost = (Fragmenttabhost) fi Ndviewbyid (Android.
R.id.tabhost);
Mtabhost.setup (this, Getsupportfragmentmanager (), r.id.realtabcontent);
int count = Fragmentarray.length; for (int i = 0; i < count; i++) {tabhost.Tabspec Tabspec = Mtabhost.newtabspec (mtextviewarray[i)). Setindicator (Gettabitemview (i));
Mtabhost.addtab (Tabspec, fragmentarray[i], NULL);
Mtabhost.gettabwidget (). Getchildat (i). Setbackgroundresource (R.color.white);
} mtabhost.setcurrenttabbytag (Mtextviewarray[0]);
Mtabhost.gettabwidget (). setdividerdrawable (NULL); /** * Item Style * @param index number * @return each tab style/private View gettabitemview (int index) {Vie
W view = layoutinflater.inflate (R.layout.tab_home_item, NULL);
ImageView ImageView = (imageview) View.findviewbyid (R.id.icon);
Imageview.setimageresource (Mimageviewarray[index]);
TextView TextView = (TextView) View.findviewbyid (r.id.name);
Textview.settext (Mtextviewarray[index]);
return view; }
}
Through the above articles, I hope to help everyone, thank you for your support to this site!