gpt4 book ai didi

android - requestWindowFeature(Window.FEATURE_NO_TITLE);给出异常(exception)

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:10:57 30 4
gpt4 key购买 nike

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

public class OptionsActivity extends PreferenceActivity {
private ListPreference mListPreference;

@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

addPreferencesFromResource(R.xml.options);
mListPreference = (ListPreference) findPreference("listpreference");
mListPreference.setPersistent(false);

}
}

Exception Stacktrace is given below:
01-27 12:35:51.920: ERROR/AndroidRuntime(615): FATAL EXCEPTION: main
01-27 12:35:51.920: ERROR/AndroidRuntime(615): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.game/com.android.game.OptionsActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at android.os.Handler.dispatchMessage(Handler.java:99)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at android.os.Looper.loop(Looper.java:123)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at java.lang.reflect.Method.invokeNative(Native Method)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at java.lang.reflect.Method.invoke(Method.java:521)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at dalvik.system.NativeStart.main(Native Method)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:172)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at android.app.Activity.requestWindowFeature(Activity.java:2719)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at com.android.game.OptionsActivity.onCreate(OptionsActivity.java:20)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-27 12:35:51.920: ERROR/AndroidRuntime(615): ... 11 more

最佳答案

将 setRequestedOrientation() 移到 add/clearFlags() 代码之后

编辑:如下所述,我没有看到它使用了 preferenceActivity。仅供您理解,这是您使用 super.onCreate() 调用的 PreferenceActivity.onCreate():

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(com.android.internal.R.layout.preference_list_content);

mPreferenceManager = onCreatePreferenceManager();
getListView().setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
}

如果已经在 super.onCreate() 中请求了,为什么还要请求 FEATURE_NO_TITLE?如果您深入研究 Android 源代码,有时会非常有帮助。

关于android - requestWindowFeature(Window.FEATURE_NO_TITLE);给出异常(exception),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4813831/

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