2

我正在尝试在我的一个选项卡上添加一个标题并得到一个 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
4

1 回答 1

4

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

问题是:框架可能会代表您请求功能。我搜索了 android 代码库,发现只有一种情况,generateLayout()方法,在我的情况下,它请求了Window.FEATURE_ACTION_BAR因为我启用了 Holo 主题......要弄清楚的讨厌的事情,解决方法很简单,禁用全息主题

于 2012-10-25T04:42:36.677 回答