0

我已使用 actionbarsherlock 在我的应用程序中创建拆分操作栏。当我想将标题栏更改为我的自定义标题栏时,我收到以下异常

    09-20 17:29:14.893: E/AndroidRuntime(332): FATAL EXCEPTION: main
09-20 17:29:14.893: E/AndroidRuntime(332): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.xmlparsing/com.androidhive.xmlparsing.Listofcategories}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
09-20 17:29:14.893: E/AndroidRuntime(332):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-20 17:29:14.893: E/AndroidRuntime(332):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-20 17:29:14.893: E/AndroidRuntime(332):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-20 17:29:14.893: E/AndroidRuntime(332):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-20 17:29:14.893: E/AndroidRuntime(332):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-20 17:29:14.893: E/AndroidRuntime(332):  at android.os.Looper.loop(Looper.java:123)
09-20 17:29:14.893: E/AndroidRuntime(332):  at android.app.ActivityThread.main(ActivityThread.java:3683)
09-20 17:29:14.893: E/AndroidRuntime(332):  at java.lang.reflect.Method.invokeNative(Native Method)
09-20 17:29:14.893: E/AndroidRuntime(332):  at java.lang.reflect.Method.invoke(Method.java:507)
09-20 17:29:14.893: E/AndroidRuntime(332):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-20 17:29:14.893: E/AndroidRuntime(332):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-20 17:29:14.893: E/AndroidRuntime(332):  at dalvik.system.NativeStart.main(Native Method)
09-20 17:29:14.893: E/AndroidRuntime(332): Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
09-20 17:29:14.893: E/AndroidRuntime(332):  at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:192)
09-20 17:29:14.893: E/AndroidRuntime(332):  at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2110)
09-20 17:29:14.893: E/AndroidRuntime(332):  at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2261)
09-20 17:29:14.893: E/AndroidRuntime(332):  at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1427)
09-20 17:29:14.893: E/AndroidRuntime(332):  at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:902)
09-20 17:29:14.893: E/AndroidRuntime(332):  at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:853)
09-20 17:29:14.893: E/AndroidRuntime(332):  at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:218)
09-20 17:29:14.893: E/AndroidRuntime(332):  at com.androidhive.xmlparsing.Listofcategories.onCreate(Listofcategories.java:106)
09-20 17:29:14.893: E/AndroidRuntime(332):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-20 17:29:14.893: E/AndroidRuntime(332):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-20 17:29:14.893: E/AndroidRuntime(332):  ... 11 more

我的代码片段是

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.maincategories);
    actionbar=getSupportActionBar();
     getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
4

2 回答 2

4

要使用 actionbar sherlock 放置自定义标题栏,您需要执行以下操作:

View actionbar = LayoutInflater.from(this).inflate(R.layout.actionbar, null);
getSupportActionBar().setCustomView(actionbar);
getSupportActionBar().setDisplayShowCustomEnabled(true);
于 2012-09-20T08:04:34.453 回答
0

Theme.Sherlock继承自Sherlock.__Theme,而后者又继承自android:Theme.NoTitleBar

 <style name="Theme.NoTitleBar">
     <item name="android:windowNoTitle">true</item>
 </style>

这与requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

于 2012-09-20T08:05:11.317 回答