此为主界面,可能与本系列的第三篇有相似,因为我在此activity中设置了默认的HomeActivity,当中使用了tabHost实现,好了,贴代码,在此说明一下,可能代码里调用一些方法在本篇中没有,但是全部在我的代码里,也不要索取图片,要看全部代码的请移步http://blog.csdn.net/gaojin1991/article/details/8022213
<?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="@drawable/bg_activitycontent">
<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:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.0"
/>
<RadioGroup
android:id="@+id/mainactivitytoolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#BB768e95"
android:layout_gravity="bottom"
android:gravity="center_vertical">
<RadioButton
android:id="@+id/homepage"
android:tag="radiobutton_homePage"
android:layout_marginTop="2.0dip"
android:text="@string/mainActivity_homepage"
android:drawableTop="@drawable/icon_home"
style="@style/main_tab_bottom" />
<RadioButton
android:id="@+id/message"
android:tag="radiobutton_message"
android:layout_marginTop="2.0dip"
android:text="@string/mainActivity_message"
android:drawableTop="@drawable/icon_message"
style="@style/main_tab_bottom" />
<RadioButton
android:id="@+id/goodfrends"
android:tag="radiobutton_selfinfo"
android:layout_marginTop="2.0dip"
android:text="@string/mainActivity_goodfrends"
android:drawableTop="@drawable/icon_goodfrends"
style="@style/main_tab_bottom" />
<RadioButton
android:id="@+id/search"
android:tag="radiobutton_search"
android:layout_marginTop="2.0dip"
android:text="@string/mainActivity_search"
android:drawableTop="@drawable/icon_search"
style="@style/main_tab_bottom" />
<RadioButton
android:id="@+id/more"
android:tag="radiobutton_more"
android:layout_marginTop="2.0dip"
android:text="@string/mainActivity_more"
android:drawableTop="@drawable/icon_more"
style="@style/main_tab_bottom"/>
</RadioGroup>
</LinearLayout>
</TabHost>
package com.czu.sinaweibo;
import com.czu.sinaweibo.R;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.TabHost;
public class MainActivity extends TabActivity {
private TabHost tabHost = null;
private RadioGroup radioGroup = null;
private static final String TAB_HOME = "tab_home";
private static final String TAB_MESSAGE = "tab_message";
private static final String TAB_GOODFRENDS = "tab_selfgoodfrends";
private static final String TAB_SEARCH = "tab_search";
private static final String TAB_MORE = "tab_more";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main_activity);
tabHost = getTabHost();
radioGroup = (RadioGroup) this.findViewById(R.id.mainactivitytoolbar);
tabHost.addTab(tabHost.newTabSpec(TAB_HOME).setIndicator(TAB_HOME)
.setContent(new Intent(MainActivity.this, HomeActivity.class)));
tabHost.addTab(tabHost
.newTabSpec(TAB_MESSAGE)
.setIndicator(TAB_MESSAGE)
.setContent(
new Intent(MainActivity.this, MessageActivity.class)));
tabHost.addTab(tabHost
.newTabSpec(TAB_GOODFRENDS)
.setIndicator(TAB_GOODFRENDS)
.setContent(
new Intent(MainActivity.this, GoodFrendsActivity.class)));
tabHost.addTab(tabHost.newTabSpec(TAB_SEARCH).setIndicator(TAB_SEARCH)
.setContent(new Intent(MainActivity.this, FindActivity.class)));
tabHost.addTab(tabHost.newTabSpec(TAB_MORE).setIndicator(TAB_MORE)
.setContent(new Intent(MainActivity.this, MoreActivity.class)));
tabHost.setCurrentTab(0);
radioGroup
.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.homepage:
tabHost.setCurrentTabByTag(TAB_HOME);
break;
case R.id.message:
tabHost.setCurrentTabByTag(TAB_MESSAGE);
break;
case R.id.goodfrends:
tabHost.setCurrentTabByTag(TAB_GOODFRENDS);
break;
case R.id.search:
tabHost.setCurrentTabByTag(TAB_SEARCH);
break;
case R.id.more:
tabHost.setCurrentTabByTag(TAB_MORE);
break;
default:
break;
}
}
});
}
}