在 android.app.Fragment 中使用制表符?
Using Tabs inside android.app.Fragment?
如何创建顶部带有选项卡的 Fragment,以托管其他 Fragment?
我以前使用 android.support.v4.app.Fragment
,但由于 PreferenceFragment
class 而改用 android.app.Fragment
。我的代码是:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_tabs,container, false);
mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("fragmentb").setIndicator("Fragment B"),
FragmentB.class, null);
return rootView;
}
但这不再有效,因为 setup
需要 v4-FragmentManager。
有什么解决这个问题的建议吗?
提前致谢!
作为@SubinSebastian answered here :
将以下项目作为库项目添加到您的应用程序中。
https://github.com/kolavar/android-support-v4-preferencefragment
此解决方案优于所有其他解决方案。将此项目作为库项目添加到您的工作区。您可以保留所有内容,包括您的片段事务,并且在导入 PreferenceFragment 时按以下方式执行。
import android.support.v4.preference.PreferenceFragment;
而不是
import android.preference.PreferenceFragment;
如何创建顶部带有选项卡的 Fragment,以托管其他 Fragment?
我以前使用 android.support.v4.app.Fragment
,但由于 PreferenceFragment
class 而改用 android.app.Fragment
。我的代码是:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_tabs,container, false);
mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("fragmentb").setIndicator("Fragment B"),
FragmentB.class, null);
return rootView;
}
但这不再有效,因为 setup
需要 v4-FragmentManager。
有什么解决这个问题的建议吗?
提前致谢!
作为@SubinSebastian answered here :
将以下项目作为库项目添加到您的应用程序中。
https://github.com/kolavar/android-support-v4-preferencefragment
此解决方案优于所有其他解决方案。将此项目作为库项目添加到您的工作区。您可以保留所有内容,包括您的片段事务,并且在导入 PreferenceFragment 时按以下方式执行。
import android.support.v4.preference.PreferenceFragment;
而不是
import android.preference.PreferenceFragment;