我想像那张图片制作一个TabHost。我可以使用自己的图像作为TabWidget的背景。 :
并想要删除默认背景(在此图片中以红色箭头显示)。这样做的代码。
<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="5dp">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_weight="1"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="@drawable/navbar_glass"/>
</LinearLayout>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
//tabHost.getTabWidget().setStripEnabled(false);
tabHost.getTabWidget().setFocusable(false);
// Tab for Photos
TabSpec photospec = tabHost.newTabSpec("Chats");
photospec.setIndicator("Chats", getResources().getDrawable(R.drawable.chat_button));
Intent photosIntent = new Intent(this, PhotosActivity.class);
photospec.setContent(photosIntent);
TabSpec photospec2 = tabHost.newTabSpec("Friends");
photospec2.setIndicator("Friends", getResources().getDrawable(R.drawable.friend_button));
Intent photosIntent2 = new Intent(this, PhotosActivity.class);
photospec2.setContent(photosIntent2);
// Tab for Songs
TabSpec songspec = tabHost.newTabSpec("Library");
// setting Title and Icon for the Tab
songspec.setIndicator("Library", getResources().getDrawable(R.drawable.library_button));
Intent songsIntent = new Intent(this, SongsActivity.class);
songspec.setContent(songsIntent);
// Tab for Videos
TabSpec videospec = tabHost.newTabSpec("Settings");
videospec.setIndicator("Settings", getResources().getDrawable(R.drawable.setting_button));
Intent videosIntent = new Intent(this, VideosActivity.class);
videospec.setContent(videosIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(photospec); // Adding photos tab
tabHost.addTab(songspec); // Adding songs tab
tabHost.addTab(videospec); // Adding videos tab
tabHost.addTab(photospec2);
}
`