TabHost 添加底部菜單

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/page_bg" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0.0dip"
            android:layout_weight="1.0" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.0"
            android:visibility="gone" />

        <RadioGroup
            android:id="@+id/main_radio"
            android:layout_width="fill_parent"
            android:layout_height="65dp"
            android:layout_gravity="bottom"
            android:background="@drawable/main_tab_bg"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

            <RadioButton
                android:id="@+id/radio_button0"
                style="@style/main_tab_bottom"
                android:layout_marginBottom="3dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="3dp"
                android:checked="true"
                android:drawableTop="@drawable/main_jiong_icon"
                android:tag="radio_button0"
                android:text="首頁" />

            <RadioButton
                android:id="@+id/radio_button1"
                style="@style/main_tab_bottom"
                android:layout_marginBottom="3dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="3dp"
                android:drawableTop="@drawable/main_shen_icon"
                android:tag="radio_button1"
                android:text="分類" />

            <RadioButton
                android:id="@+id/radio_button2"
                style="@style/main_tab_bottom"
                android:layout_marginBottom="3dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="3dp"
                android:drawableTop="@drawable/main_high_icon"
                android:tag="radio_button2"
                android:text="商城" />

            <RadioButton
                android:id="@+id/radio_button3"
                style="@style/main_tab_bottom"
                android:layout_marginBottom="3dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="3dp"
                android:drawableTop="@drawable/main_more_icon"
                android:tag="radio_button3"
                android:text="個人中心" />
        </RadioGroup>
    </LinearLayout>

</TabHost>



public class TabPageActivity extends TabActivity {
	public TabHost mth;
	public static final String TAB_ONE= "首頁";
	public static final String TAB_TWO = "分類";
	public static final String TAB_THREE = "商城";
	public static final String TAB_FOUR  = "個人中心";
	public RadioGroup radioGroup;
	public static boolean unlock = false;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main); 
		
		this.initTableHost();

	}


	private void initTableHost() {
		mth = this.getTabHost();

		TabSpec ts1 = mth.newTabSpec(TAB_ONE).setIndicator(TAB_ONE);
		ts1.setContent(new Intent(TabPageActivity.this, HomePageActivity.class));
		mth.addTab(ts1);

		TabSpec ts2 = mth.newTabSpec(TAB_TWO).setIndicator(TAB_TWO);
		ts2.setContent(new Intent(TabPageActivity.this, FenLeiActivity.class));
		mth.addTab(ts2);
		
		TabSpec ts3 = mth.newTabSpec(TAB_THREE).setIndicator(TAB_THREE);
		Intent intent = new Intent(TabPageActivity.this,
				ShangchengWebViewActivity.class);
		intent.putExtra( Constants.WEB_VIEW_URL, "http://www.baidu.com");
		intent.putExtra(Constants.MENU_NAME, "商城");
		ts3.setContent(intent);
		mth.addTab(ts3);

		

		TabSpec ts4 = mth.newTabSpec(TAB_FOUR).setIndicator(TAB_FOUR);
		ts4.setContent(new Intent(TabPageActivity.this, MoreActivity.class));
		mth.addTab(ts4);

		this.radioGroup = (RadioGroup) findViewById(R.id.main_radio);
		mth.setCurrentTabByTag(TAB_ONE);
		radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.radio_button0:
					mth.setCurrentTabByTag(TAB_ONE);
					break;
				case R.id.radio_button1:
					mth.setCurrentTabByTag(TAB_TWO);
					break;
				case R.id.radio_button2:
					mth.setCurrentTabByTag(TAB_THREE);
					break;
				case R.id.radio_button3:
					mth.setCurrentTabByTag(TAB_FOUR);
					break;

				}
			}
		});
		
	}

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章