Android 自定义TabHost风格

fmms 13年前

main.xml

<?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  &nbsp;&nbsp;&nbsp; android:orientation="vertical"  &nbsp;&nbsp;&nbsp; android:layout_width="fill_parent"  &nbsp;&nbsp;&nbsp; android:layout_height="fill_parent"  &nbsp;&nbsp;&nbsp; >  <TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent">  &nbsp;&nbsp;&nbsp; <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:layout_height="match_parent" android:orientation="vertical">  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <TabWidget android:layout_width="match_parent" android:id="@android:id/tabs" android:layout_height="wrap_content"></TabWidget>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabcontent">    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1">  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <ImageView android:id="@+id/imageView2" android:src="@drawable/intnet" android:layout_width="match_parent" android:layout_height="match_parent"></ImageView>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </LinearLayout>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2">  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <ImageView android:id="@+id/imageView4" android:src="@drawable/reresh" android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </LinearLayout>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab3">  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <ImageView android:id="@+id/imageView5" android:src="@drawable/search" android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </LinearLayout>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab4">  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <ImageView android:id="@+id/imageView3" android:src="@drawable/picture" android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </LinearLayout>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab5">  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <ImageView android:id="@+id/imageView1" android:src="@drawable/info" android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </LinearLayout>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FrameLayout>  &nbsp;&nbsp;&nbsp; </LinearLayout>  </TabHost>  </LinearLayout>
Activity
package rw.Tab;    import android.app.TabActivity;  import android.os.Bundle;  import android.widget.TabHost;    public class Tabhost02Activity extends TabActivity {      /** Called when the activity is first created. */    private TabHost tabHost;      @Override      public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.main);          tabHost=getTabHost();          tabHost.addTab(tabHost.newTabSpec("network").setIndicator("流量",getResources().getDrawable(R.drawable.intnet)).setContent(R.id.tab1));          tabHost.addTab(tabHost.newTabSpec("refesh").setIndicator("刷新",getResources().getDrawable(R.drawable.reresh)).setContent(R.id.tab2));          tabHost.addTab(tabHost.newTabSpec("search").setIndicator("搜索",getResources().getDrawable(R.drawable.search)).setContent(R.id.tab3));          tabHost.addTab(tabHost.newTabSpec("picture").setIndicator("图片",getResources().getDrawable(R.drawable.picture)).setContent(R.id.tab4));          tabHost.addTab(tabHost.newTabSpec("info").setIndicator("信息",getResources().getDrawable(R.drawable.info)).setContent(R.id.tab5));                }  }
Android 自定义TabHost风格