TabWidget
AndroidTabWidget/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{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.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);
}
} 相关推荐
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