【问题标题】:Integrate tabs in fragment在片段中集成选项卡
【发布时间】:2013-12-10 05:49:43
【问题描述】:

我有一个扩展 Fragment 的 Activity。我想在 Fragment 中添加一个选项卡。

在这个活动中我想添加两个标签

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;

public class Fragment_Coupons extends Fragment {
    TabHost tabHost;
    TabHost.TabSpec spec;

    public Fragment_Coupons() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_coupon, container,
                false);

        return rootView;
    }

}

【问题讨论】:

    标签: android android-fragments android-tabs


    【解决方案1】:

    首先

    任何扩展Fragment的东西都是Fragment,你不能有一个扩展Fragment的Activity

    如果你想了解标签,你可以阅读Adding Navigation Tabs

    1. 基本上你需要为操作栏设置导航类型

      ActionBar actionBar = getSupportActionBar();
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
      
    2. 将您想要的 2 个选项卡添加到操作栏

         Tab tab = actionBar.newTab()
                             .setText(R.string.artist)
                             .setTabListener(new TabListener<ArtistFragment>(
                                     this, "artist", ArtistFragment.class));
          actionBar.addTab(tab);
      
          tab = actionBar.newTab()
                         .setText(R.string.album)
                         .setTabListener(new TabListener<AlbumFragment>(
                                 this, "album", AlbumFragment.class));
          actionBar.addTab(tab);
      
    3. 实现 ActionBar.TabListener 接口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-04
      • 2013-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多