java - android TabsHost 未在使用 SDK 22 的 Fragment 中显示

标签 java android android-fragments tabs

我是 Android 新手,我的问题是当我将 TabHost 放入 Fragment 中时,它在运行我的应用程序后没有显示!我不确定我是否以正确的方式做这件事!或者部分代码丢失。这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <TabHost
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/tabHost"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"></TabWidget>

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

                <LinearLayout
                    android:id="@+id/tab1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"></LinearLayout>

                <LinearLayout
                    android:id="@+id/tab2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"></LinearLayout>

                <LinearLayout
                    android:id="@+id/tab3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"></LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>
</RelativeLayout>
<小时/>
package com.hesabgar.hesabgar;

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

    public class FindPeopleFragment extends Fragment {

    public FindPeopleFragment(){}


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


        View rootView = inflater.inflate(R.layout.fragment_find_people, container, false);
  // What should i put here ? ?? ? ??
        return rootView;
    }


    }

最佳答案

尝试:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.your_layout, container, false);
    TabHost tabHost = (TabHost) view.findViewById(R.id.profile_tabs);
    tabHost.setup();
    tabHost.addTab(...);
    tabHost.addTab(...);
    return view;
}

关于java - android TabsHost 未在使用 SDK 22 的 Fragment 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31295971/

相关文章:

android - 在 AlertDialog 中更改 ListView 的字体大小

java - Android - 在 native 应用程序和 Java 应用程序之间使用管道

android - 将序列化对象传递给 fragment

java - 将实时数据从 Viewpager Fragment 共享到 Activity

java - 使用二维数组排序

java - 无法检查 AlertDialog.Builder 中 EditText 的值

java - 如何从设备读取和写入超大数据

java - 将多个测试运行合并到一个 Jacoco.exec 文件中

javascript - Android - ProGuard 引起所有 JavascriptInterface 使用的警告

android - 在 MVVM 架构中从 ViewModel 添加 fragment