先说布局文件,如下:利用android:layout_alignParentBottom="true" 实现底部显示
1 27 11 4215 1619 4123 >3028 29 34 4038 39
下面是主程序代码,注释写的比较详细,这里就不在多解释了
1 package com.cloay; 2 3 import android.app.TabActivity; 4 import android.graphics.Color; 5 import android.os.Bundle; 6 import android.widget.TabHost; 7 import android.widget.TabHost.OnTabChangeListener; 8 import android.widget.Toast; 9 10 public class TabTestActivity extends TabActivity {11 TabHost tabHost;12 @Override13 public void onCreate(Bundle savedInstanceState) {14 super.onCreate(savedInstanceState);15 setContentView(R.layout.main);16 //获取TabHost对象17 tabHost = getTabHost(); 18 // tabHost.setup();19 //新建一个newTabSpec,设置标签和图标(setIndicator),设置内容(setContent)20 tabHost.addTab(tabHost.newTabSpec("Test one").setIndicator("",getResources().getDrawable(android.R.drawable.ic_menu_call)).setContent(R.id.tabFirst));21 tabHost.addTab(tabHost.newTabSpec("Test two").setIndicator("",getResources().getDrawable(android.R.drawable.ic_menu_camera)).setContent(R.id.tabSecond));22 //设置TabHost的背景颜色23 tabHost.setBackgroundColor(Color.argb(150,22,70,150));24 //设置TabHost的背景图片资源25 // tabHost.setBackgroundResource(R.drawable.bg);26 //设置当前现实哪一个标签27 tabHost.setCurrentTab(0); //0为标签ID28 //标签切换处理,用setOnTabChangedListener 29 tabHost.setOnTabChangedListener(new OnTabChangeListener(){30 public void onTabChanged(String tabId){31 Toast.makeText(TabTestActivity.this, "This is a Test!", Toast.LENGTH_LONG).show();32 }33 });34 }35 }