Android TabWidget/TabHost有两种使用方法:
第一种:使用系统自带写好的TabHost(及继承自TabActivity类)
第二种:就是定义我们自己的tabHost:不用继承TabActivity
这里我们使用第二章自定义tabHost的方法实现
示例:
main.xml
<?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"    >    <LinearLayout android:orientation="vertical" android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:padding="5dip">    <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent"    android:layout_height="wrap_content"     />    <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:padding="5dip">    </FrameLayout>      </LinearLayout></TabHost>

Activity.java
public class MainActivity extends TabActivity{@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);TabHost tabHost=this.getTabHost();Intent remoteIntent=new Intent();remoteIntent.setClass(this, mp3player.class);//内部类的写法,TabSpec代表一页的内容TabHost.TabSpec remoteSpec=tabHost.newTabSpec("remote");//使用android内部的图标,也可以使用自行下载的图片  代表了一页Resources res=this.getResources();remoteSpec.setIndicator("remote", res.getDrawable(android.R.drawable.arrow_down_float));remoteSpec.setContent(remoteIntent);tabHost.addTab(remoteSpec);Intent localIntent=new Intent();localIntent.setClass(this, LocalActivity.class);TabHost.TabSpec localSpec=tabHost.newTabSpec("local");localSpec.setIndicator("local", res.getDrawable(android.R.drawable.arrow_down_float));localSpec.setContent(localIntent);tabHost.addTab(localSpec);}}

更多相关文章

  1. android 不透明度16进制值
  2. Android(安卓)给Animation设置setRepeatMode不起作用
  3. Android(安卓)selector 的shape、gradient、stroke、corners 、s
  4. Android(安卓)MediaPlayer Error/Info Code
  5. android开发:activity继承AppCompatActivity 去掉标题栏
  6. 从头学Android之多媒体--使用MediaRecorder录制音频
  7. java 非静态内部类为什么持有外部类的引用
  8. 【Android(安卓)开发教程】注册事件监听器
  9. android 开机动画的制作

随机推荐

  1. Android(安卓)帧动画 AnimationDrawable
  2. 用Android-X86和VirtualBox打造高性能And
  3. 怎么P手持身份證照片SFZ(分布解说)
  4. php:1. 单文件上传与多文件上传 2. 简单
  5. 大家好,有朋自远方来,不亦说乎,请多关照哈
  6. 大家好啊,新手一枚,请多关照哈
  7. 字符串学习
  8. php分支与循环 、php与html混编学习
  9. 刚才看到一个P身份證的楼主P出来假的不得
  10. 单文件上传与多文件上传,简单分页操作的