从SherlockFragment设置Actionbar叠加层

时间:2014-04-17 06:52:49

标签: android actionbarsherlock fragment overlay

我想在ActionbarOverlay课程中设置SherlockFragment功能。 任何人都可以告诉我,我该怎么做?

我尝试在getSherlockActivity().requestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);方法中添加行OnCreateView

但它给了我错误:

04-17 12:19:35.789: E/AndroidRuntime(844): FATAL EXCEPTION: main
04-17 12:19:35.789: E/AndroidRuntime(844): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
04-17 12:19:35.789: E/AndroidRuntime(844):  at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:210)
04-17 12:19:35.789: E/AndroidRuntime(844):  at com.oceans.sherelock.internal.ActionBarSherlockNative.requestFeature(ActionBarSherlockNative.java:97)
04-17 12:19:35.789: E/AndroidRuntime(844):  at com.oceans.sherelock.app.SherlockFragmentActivity.requestWindowFeature(SherlockFragmentActivity.java:276)
04-17 12:19:35.789: E/AndroidRuntime(844):  at com.wallpapermaker.keepcalm.UserProfile_NoBoringFragment.onCreateView(UserProfile_NoBoringFragment.java:92)
04-17 12:19:35.789: E/AndroidRuntime(844):  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
04-17 12:19:35.789: E/AndroidRuntime(844):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
04-17 12:19:35.789: E/AndroidRuntime(844):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
04-17 12:19:35.789: E/AndroidRuntime(844):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
04-17 12:19:35.789: E/AndroidRuntime(844):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
04-17 12:19:35.789: E/AndroidRuntime(844):  at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
04-17 12:19:35.789: E/AndroidRuntime(844):  at android.os.Handler.handleCallback(Handler.java:605)
04-17 12:19:35.789: E/AndroidRuntime(844):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-17 12:19:35.789: E/AndroidRuntime(844):  at android.os.Looper.loop(Looper.java:137)
04-17 12:19:35.789: E/AndroidRuntime(844):  at android.app.ActivityThread.main(ActivityThread.java:4424)
04-17 12:19:35.789: E/AndroidRuntime(844):  at java.lang.reflect.Method.invokeNative(Native Method)
04-17 12:19:35.789: E/AndroidRuntime(844):  at java.lang.reflect.Method.invoke(Method.java:511)
04-17 12:19:35.789: E/AndroidRuntime(844):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-17 12:19:35.789: E/AndroidRuntime(844):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-17 12:19:35.789: E/AndroidRuntime(844):  at dalvik.system.NativeStart.main(Native Method)

P.S。我无法在Activity内设置它,因为我不希望为我的Activity中的其他片段启用叠加功能。

1 个答案:

答案 0 :(得分:0)

您必须在活动中调用setContent之前调用

getSherlockActivity().requestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);

在您的活动中添加内容视图之前添加此内容。

我希望它有所帮助。

<强> 更新

然后在你的片段中扩展第一个SherlockFragment 然后在调用setContentView方法之前将代码放在Activity的OnCreate方法中。

getSherlock().requestFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
抱歉,我的错 再次检查更新。