0
    <?xml version="1.0" encoding="UTF-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/background" >

        <TabHost
            android:id="@android:id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="fill_parent" >

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_above="@+id/tabs" />

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:background="@drawable/button"
                    android:divider="@drawable/dividerd" />
            </RelativeLayout>
        </TabHost>

    </RelativeLayout>




 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.mainpage);

        System.out.println("..........after layout...........");

        tabHost = getTabHost();
   tabHost.addTab(tabHost.newTabSpec("Payment").setIndicator("Acticvity 1",getResources().getDrawable(R.drawable.homed))
                        .setContent(new Intent(this, Activity 1.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

请找到 xml 文件代码和活动代码。当我打开应用程序时,我看不到任何选项卡。请帮助我。像上面一样,我有 4 个这样的标签要显示,但它们都没有显示

4

4 回答 4

0

改变你的框架布局

<FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@+id/tabs" />

使用 android:layout_above="@android:id/tabs"

于 2012-07-30T10:39:45.703 回答
0
 public class TabsActivity extends TabActivity {

private TabHost tabHost;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.tabs_layout);

    tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabCreation();
    tabHost.setOnTabChangedListener(new OnTabChangeListener() {
        public void onTabChanged(String tabId) {
            if (tabId.equals("Contacts")) {
                Log.i("Tab", "change");
            }
        }
    });
}

void tabCreation() {

    tabHost.setup();

    TabSpec spec1 = tabHost.newTabSpec("Accounts");

    spec1.setIndicator(createTabView(TabsActivity.this, "Accounts",
            R.drawable.tab_home));
    spec1.setContent(new Intent(TabsActivity.this, AccountsActivity.class));

    TabSpec spec2 = tabHost.newTabSpec("Contacts");

    spec2.setIndicator(createTabView(tabHost.getContext(), "Contacts",
            R.drawable.tab_account));
    spec2.setContent(new Intent(TabsActivity.this, ContactsActivity.class));

    TabSpec spec3 = tabHost.newTabSpec("Chats");

    spec3.setIndicator(createTabView(tabHost.getContext(), "Chats",
            R.drawable.tab_settings));
    spec3.setContent(new Intent(TabsActivity.this, ChatsActivity.class));

    TabSpec spec4 = tabHost.newTabSpec("More");
    spec4.setIndicator(createTabView(tabHost.getContext(), "More",
            R.drawable.tab_more));
    spec4.setContent(new Intent(TabsActivity.this, ChatsActivity.class));

    tabHost.addTab(spec1);
    tabHost.addTab(spec2);
    tabHost.addTab(spec3);
    tabHost.addTab(spec4);

    tabHost.setCurrentTab(0);
}

private static View createTabView(final Context context, final String text,
        final int id) {

    View view = LayoutInflater.from(context).inflate(
            R.layout.tab_indicator, null);
    TextView tv = (TextView) view.findViewById(R.id.title);
    tv.setText(text);
    ImageView icon = (ImageView) view.findViewById(R.id.icon);
    icon.setImageResource(id);
    return view;
}

}

于 2012-07-30T10:52:46.403 回答
0
MAin Activity
 import android.app.TabActivity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class AndroidTabLayoutActivity extends TabActivity {
  /** Called when the activity is first created. */
   @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
        TabHost tabHost = getTabHost();

      // Tab for Photos
       TabSpec photospec = tabHost.newTabSpec("photos");
       photospec.setIndicator("chat",     getResources().getDrawable(R.drawable.icon_photos_tab));
    Intent photosIntent = new Intent(this, PhotosActivity.class);
    photospec.setContent(photosIntent);


    // Tab for Songs
    TabSpec songspec = tabHost.newTabSpec("songs");
    // setting Title and Icon for the Tab
    songspec.setIndicator("contacts", getResources().getDrawable(R.drawable.icon_songs_tab));
    Intent songsIntent = new Intent(this, SongsActivity.class);
    songspec.setContent(songsIntent);


    // Tab for Videos
    TabSpec videospec = tabHost.newTabSpec("videos");
    videospec.setIndicator("Accounts", getResources().getDrawable(R.drawable.icon_videos_tab));
    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
 }
 }
于 2012-07-30T11:19:41.123 回答
0
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TabHost
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="0dp" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="55dp"
            android:tabStripEnabled="false" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >


        </FrameLayout>
    </LinearLayout>
</TabHost>

于 2012-07-30T10:37:03.797 回答