TabHost无法将自定义标题与其他标题功能组合在一起

时间:2012-08-29 15:09:32

标签: java android

我正在尝试在我的某个标签上添加标题并获得了一个java异常: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features

相同的代码在Android v4.x上完美运行,但无法在v2.2x上运行

  • 有人可以帮我解决这个问题吗?

注意:我还使用ActionBarCompat

提供的Google

我的Java代码:

public class MyNotepadActivity extends TabActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD){
           requestWindowFeature(Window.FEATURE_NO_TITLE); 
           this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        setContentView(R.layout.main);
        Resources res = getResources();
        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;

        Intent intent;
        intent = new Intent().setClass(this.getApplicationContext(),
        NotationActivity.class);
        spec = tabHost.newTabSpec("Notation").setIndicator("detail Note").setContent(intent);
        tabHost.addTab(spec);
    }
}

堆栈跟踪:

08-29 08:39:39.329: W/dalvikvm(3063): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
08-29 08:39:39.349: E/AndroidRuntime(3063): FATAL EXCEPTION: main
08-29 08:39:39.349: E/AndroidRuntime(3063): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.biblio/org.biblio.MyNotepadActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.biblio/org.biblio.MyNotepadActivity}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.os.Handler.dispatchMessage(Handler.java:99)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.os.Looper.loop(Looper.java:144)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.ActivityThread.main(ActivityThread.java:4937)
08-29 08:39:39.349: E/AndroidRuntime(3063): at java.lang.reflect.Method.invokeNative(Native Method)
08-29 08:39:39.349: E/AndroidRuntime(3063): at java.lang.reflect.Method.invoke(Method.java:521)
08-29 08:39:39.349: E/AndroidRuntime(3063): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-29 08:39:39.349: E/AndroidRuntime(3063): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-29 08:39:39.349: E/AndroidRuntime(3063): at dalvik.system.NativeStart.main(Native Method)
08-29 08:39:39.349: E/AndroidRuntime(3063): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.biblio/org.biblio.NotationActivity}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2627)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.widget.TabHost.setCurrentTab(TabHost.java:323)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.widget.TabHost.addTab(TabHost.java:213)
08-29 08:39:39.349: E/AndroidRuntime(3063): at org.biblio.MyBookActivity.onCreate(MyBookActivity.java:70)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
08-29 08:39:39.349: E/AndroidRuntime(3063): ... 11 more
08-29 08:39:39.349: E/AndroidRuntime(3063): Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features 
08-29 08:39:39.349: E/AndroidRuntime(3063): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:187)
 08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.Activity.requestWindowFeature(Activity.java:2760)
08-29 08:39:39.349: E/AndroidRuntime(3063): at org.biblio.ui.actionbarcompat.ActionBarHelperBase.onCreate(ActionBarHelperBase.java:64)
08-29 08:39:39.349: E/AndroidRuntime(3063): at org.biblio.ui.actionbarcompat.ActionBarActivity.onCreate(ActionBarActivity.java:53)
08-29 08:39:39.349: E/AndroidRuntime(3063): at org.biblio.SearchSudocActivity.onCreate(SearchSudocActivity.java:90)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
08-29 08:39:39.349: E/AndroidRuntime(3063): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
08-29 08:39:39.349: E/AndroidRuntime(3063): ... 20 more

1 个答案:

答案 0 :(得分:4)

如果您设置了Window.FEATURE_CUSTOM_TITLE,则无法再次调用setFeatureInt()。对它的调用将归结为Window实现中的requestFeature()调用,该方法测试FEATURE_CUSTOM_TITLE并抛出异常(如果已设置)。

问题是:框架可能代表您请求功能。我搜索了android代码库,发现只有一个这样的情况,generateLayout()方法,在我的情况下它请求了Window.FEATURE_ACTION_BAR,因为我启用了Holo主题......讨厌的事情,解决方法很简单,disabled the Holo theme