gpt4 book ai didi

java - TabHost 无法将自定义标题与其他标题功能组合

转载 作者:搜寻专家 更新时间:2023-11-01 08:08:27 26 4
gpt4 key购买 nike

我试图在我的其中一个选项卡上添加标题,但出现了 Java 异常:android.util.AndroidRuntimeException:您不能将自定义标题与其他标题功能结合使用

相同的代码在 Android v4.x 上运行良好,但在 v2.2x 上运行不正常

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

注意:我还使用 Google 提供的 ActionBarCompat

下面是我的 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

最佳答案

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

问题是:框架可能会代表您请求功能。我搜索了 android 代码库,发现只有一种情况,generateLayout()方法,在我的例子中,它请求了 Window.FEATURE_ACTION_BAR,因为我启用了 Holo 主题......很难弄清楚,解决方法很简单,disabled the Holo theme

关于java - TabHost 无法将自定义标题与其他标题功能组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12181097/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com