1.TabHost
布局文件:
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
/>
//得到当前activity中的tabhost对象
TabHost tabHost=getTabHost();
//定义tabhost中的spec
TabHost.TabSpec spec;
//定义intent对象
Intent i;
//设置第一个标签页的布局
i=new Intent(this,
MyFriendActivity.class);
spec=tabHost.newTabSpec("0").setIndicator("好友").setContent(i);
//添加到tabhost中
tabHost.addTab(spec);
扩展:clearAlltabs方法:可以清楚所有的标签页;
getCurrentTab方法:可以得到当前所选的标签页的ID;
setCurrentTab方法:可以设置当前TabHost所选中的标签页;
public
boolean onkeyDown(int keycode ,keyEvent event){
if(keycode==keyEvent.KEYCODE_BACK&&event.getRepeatCount()==0){
creatdialog():
return false;
调用方法;
2.监听手机返回键的方法
}
}