大家好,我正在使用 TabHost 在 android 中创建 TabBar....
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>
but the problem is that whenever the contents of the tab grow eg displaying dynamic content in listview against a tab then the TabHost becomes INVISIBLE..
在这方面的任何帮助将不胜感激....