1

我想制作一个像该图像一样的 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);
}

`

4

0 回答 0