public class TabBarActivity extends TabActivity implements OnTabChangeListener
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, CustomizedListView.class);
spec = tabHost.newTabSpec("Clubs").setIndicator("Clubs", getResources().getDrawable(R.drawable.clubs_icon))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Events.class);
spec = tabHost.newTabSpec("Events").setIndicator("Events", getResources().getDrawable(R.drawable.events_icon))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Maps.class);
spec = tabHost.newTabSpec("Maps").setIndicator("Maps", getResources().getDrawable(R.drawable.maps_icon))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Settings.class);
spec = tabHost.newTabSpec("Settings").setIndicator("Settings", getResources().getDrawable(R.drawable.settings_icon))
.setContent(intent);
tabHost.addTab(spec);
getTabHost().setOnTabChangedListener(this);
}
@Override
public void onTabChanged(String tabId)
{
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Inside the new tab ", Toast.LENGTH_SHORT).show();
//getTabHost().setVisibility(View.VISIBLE);
}
}
**tab.xml**
<?xml version="1.0" encoding="utf-8"?>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@android:id/tabs">
</TabWidget>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabcontent">
</FrameLayout>
</RelativeLayout>
</TabHost>
但问题是,只要选项卡的内容增长,例如在列表视图中针对选项卡显示动态内容,TabHost就会变得无形......
在这方面的任何帮助都将受到高度赞赏....
答案 0 :(得分:0)
使用TabActivity时,请使用普通活动。然后根据您的要求使用tabspec创建TabHost。并将tabHost添加为屏幕/活动中的第一个组件。