gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:20:28 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com