2012-09-20 58 views
0

在actionbarsherlock自定义标题栏我已经使用actionbarsherlock创造我app.When拆分动作条我要的标题栏更改为我的自定义标题栏我得到以下例外问题在机器人

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

要放置一个自定义标题栏与你需要做以下动作条福尔摩斯:

View actionbar = LayoutInflater.from(this).inflate(R.layout.actionbar, null); 
getSupportActionBar().setCustomView(actionbar); 
getSupportActionBar().setDisplayShowCustomEnabled(true); 
+0

有什么我需要附上因为我得到同样的错误 – JavaGuy

+0

您可以发布完整的错误日志,我感觉你的错误是在其他地方。 – ePeace

+0

我已编辑它 – JavaGuy

0

Theme.Sherlock继承自Sherlock.__Theme,其返回从android:Theme.NoTitleBar继承。

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

这种冲突与requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

+0

它不工作。有没有其他的方式来做到这一点。我正在研究Theme.Sherlock.Light.ForceOverflow。是否有任何浅色主题 我可以使用它? – JavaGuy

+1

这适用于我:当sherlock主题作为父项时,设置' false'和'FEATURE_CUSTOM_TITLE'将起作用。 – sulai