实现的Activity代码如下:
package com.example.testandroid;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class TabHostBottom extends TabActivity {
private TabHost tabhost;
private Intent news,dingyue,picture,video;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabhostbottom);
tabhost=getTabHost();
news=new Intent(TabHostBottom.this,News.class);
tabhost.addTab(tabhost.newTabSpec("first")
.setIndicator("新闻",getResources().getDrawable(android.R.drawable.ic_menu_gallery))
.setContent(news));
dingyue=new Intent(TabHostBottom.this,Dingyue.class);
tabhost.addTab(tabhost.newTabSpec("second")
.setIndicator("订阅",getResources().getDrawable(android.R.drawable.ic_menu_share))
.setContent(dingyue));
picture=new Intent(TabHostBottom.this,Picture.class);
tabhost.addTab(tabhost.newTabSpec("third")
.setIndicator("图片", getResources().getDrawable(android.R.drawable.ic_menu_slideshow))
.setContent(picture));
video=new Intent(TabHostBottom.this,Video.class);
tabhost.addTab(tabhost.newTabSpec("fourth")
.setIndicator("视频", getResources().getDrawable(android.R.drawable.stat_notify_voicemail))
.setContent(video));
tabhost.setCurrentTab(0);
}
}
对应的界面(选项卡置于底部):
<?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" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
</FrameLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- tabStripEnabled属性去掉底部下划线与选项卡间的下划线 -->
<!-- layout_alignParentBottom属性即可将其放在底部菜单栏,注意,必须在RelativeLayout里 -->
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:tabStripEnabled="true"
android:layout_alignParentBottom="true"
android:background="#AEC1EA" >
</TabWidget>
</RelativeLayout>
</TabHost>