android的tabHost的使用
废话不多,直接介绍怎么使用
1,用几个tab,就建立几个tabActivity继承Activity即可,
2,把写好的 activity配入manifest.xml文件中
3,配置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="5dp" > <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" ></FrameLayout> </LinearLayout> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </TabHost>
4,主类MianActivity类
package com.kang.fei.tabwidget; import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.widget.TabHost; import android.widget.TabHost.TabSpec; public class HelloTabWidgetActivity extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //获取资源对象以便获取图片等资源 Resources res = getResources(); //获得Activity的TabHost对象 TabHost tabHost = getTabHost(); //声明一个可以复用的Tabspecs TabSpec spec ; Intent intent; intent = new Intent().setClass(this, ArtistsActivity.class); spec =tabHost.newTabSpec("artists").setIndicator("Artisits", res.getDrawable(R.drawable.ic_tab_artists)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, AlbumsActivity.class); spec =tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_artists)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, SongsActivity.class); spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab_artists)) .setContent(intent); tabHost.addTab(spec); //设置默认的选项卡 tabHost.setCurrentTab(2); } }
完成。
相关推荐
luoj 2011-09-13
ThedakeLaugh 2011-08-01
Rgenxiao 2011-09-08
learningITwell 2011-12-26
老菜鸟自习室 2011-12-22
whale 2019-06-26
ShareUs 2015-08-18
blueskyhk 2014-05-06
xingzhong 2013-12-30
西木 2012-12-13
PiYuqing 2012-08-03
Dliliyang 2012-04-18
wangkuifeng0 2012-02-08