Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 活动片段中的TabHost_Android_Android Fragments_Android Tabhost_Fragment Tab Host - Fatal编程技术网

Android 活动片段中的TabHost

Android 活动片段中的TabHost,android,android-fragments,android-tabhost,fragment-tab-host,Android,Android Fragments,Android Tabhost,Fragment Tab Host,我想创建一个布局,其中上半部分只是具有普通视图的某个区域,下半部分是选项卡布局 我看过一些例子,但它们都是如何在活动级别创建选项卡,即通过扩展TabHostActivity来覆盖所有活动区域。 所以我决定在活动中创建2个片段,其中较低的片段将具有tablayout。 但问题是我不能让这个片段类像TabHostActivity一样扩展片段。。。 那么,有什么帮助吗?我如何实现这一点 下面是较低片段的代码- public class PFrag extends Fragment { Vie

我想创建一个布局,其中上半部分只是具有普通视图的某个区域,下半部分是选项卡布局

我看过一些例子,但它们都是如何在活动级别创建选项卡,即通过扩展TabHostActivity来覆盖所有活动区域。 所以我决定在活动中创建2个片段,其中较低的片段将具有tablayout。 但问题是我不能让这个片段类像TabHostActivity一样扩展片段。。。 那么,有什么帮助吗?我如何实现这一点

下面是较低片段的代码-

public class PFrag extends Fragment {
    View mRoot;
    TabHost tabHost;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mRoot = inflater.inflate(R.layout.payfrag, container, false);
        try {
            Resources resources = getResources();
            tabHost = (TabHost)mRoot.findViewById(R.id.tabHost);

            Intent netbintent = new  Intent(getActivity().getApplicationContext(), NB.class);
            TabHost.TabSpec tabSpecNB = tabHost.newTabSpec("NB");
            tabSpecNB.setIndicator("", resources.getDrawable(R.drawable.netb));
            tabSpecNB.setContent(netbintent);

            Intent ccardintent = new Intent(getActivity().getApplicationContext(), Cc.class);
            TabHost.TabSpec tabSpecCc = tabHost.newTabSpec("CC");
            tabSpecCc.setIndicator("", resources.getDrawable(R.drawable.cc));
            tabSpecCc.setContent(ccardintent);


            tabHost.addTab(tabSpecNB);
            tabHost.addTab(tabSpecCc);
        } catch(Exception e) {
            AlertDialog.Builder ad = new AlertDialog.Builder(getActivity().getApplicationContext());
            ad.setMessage(e.toString());
            ad.show();
        }

        return mRoot;
    }
}

听起来你需要在你的“底部”片段中使用

另一个可以帮助你的链接


而且,它似乎只适用于API 17及以上版本,所以请务必记住这一点

我不推荐使用
FragmentTabHost
它有点难以使用,而且不需要左右滑动
TabHostActivity
也不推荐使用,请使用
SlidingTabLayout
其开放源码,易于使用和更新,并具有滑动功能


你找到问题的答案了吗?不,我有点急于完成项目,只是更改了布局--,使用简单的选项卡式布局而不是片段,我肯定会尝试一下,并在得到答案后尽快发布:)