我的Android 4.0.3应用中有一个操作栏。每个选项卡都有一些按钮(一种继续)可以更改片段而不是选项卡。我按照http://developer.android.com上的官方开发者指南进行了操作,但它不起作用。
这就是我想要的:
与Action Bar Sherlock的这种互动是否可能?
答案 0 :(得分:2)
我相信您可以通过正确覆盖制表符回调类方法onTabSelected(Tab选项卡,FragmentTransaction ft)来指定所需的制表符行为。 它应该看起来像
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// Check if the fragment is already initialized
if (mFragment == null) {
// If not, instantiate and add it to the activity
mFragment = Fragment.instantiate(mActivity, mClass.getName());
ft.add(R.id.realtabcontent, mFragment, mTag);
} else {
//Here we look if current fragment aren't default fragment for this tab
//Remember that detached fragments are still managed by system, so manage it the way u need
// If it exists, simply attach it in order to show it
// ft.attach(mFragment);
if (mFragment.getTag().equals("defaultFragment"))
ft.show(mFragment);
else {
ft.detach(mFragment);
mFragment = fragmentManager.findFragmentByTag("defaultFragment");
if (mFragment == null)
mFragment = Fragment.instantiate(mActivity, mClass.getName());
ft.add(R.id.realtabcontent, mFragment, "defaultFragment");
}
}
}