我试图在我的偏好设置屏幕上隐藏标题栏,但通常是requestWindowFeature(Window.FEATURE_NO_TITLE);
没有锻炼,有什么建议吗?
我的代码是:
我的清单:
<activity
android:name=".prefs"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="com.mittereder.rockpaper.PREFS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
爪哇:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
requestWindowFeature(Window.FEATURE_NO_TITLE);
logcat的:
08-10 00:08:07.502: E/AndroidRuntime(24457): FATAL EXCEPTION: main
08-10 00:08:07.502: E/AndroidRuntime(24457): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mittereder.rockpaper/com.mittereder.rockpaper.prefs}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
08-10 00:08:07.502: E/AndroidRuntime(24457): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2194)
08-10 00:08:07.502: E/AndroidRuntime(24457): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
08-10 00:08:07.502: E/AndroidRuntime(24457): at android.app.ActivityThread.access$600(ActivityThread.java:139)
08-10 00:08:07.502: E/AndroidRuntime(24457): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
08-10 00:08:07.502: E/AndroidRuntime(24457): at android.os.Handler.dispatchMessage(Handler.java:99)
08-10 00:08:07.502: E/AndroidRuntime(24457): at android.os.Looper.loop(Looper.java:154)
08-10 00:08:07.502: E/AndroidRuntime(24457): at android.app.ActivityThread.main(ActivityThread.java:4945)
08-10 00:08:07.502: E/AndroidRuntime(24457): at java.lang.reflect.Method.invokeNative(Native Method)
08-10 00:08:07.502: E/AndroidRuntime(24457): at java.lang.reflect.Method.invoke(Method.java:511)
08-10 00:08:07.502: E/AndroidRuntime(24457): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-10 00:08:07.502: E/AndroidRuntime(24457): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-10 00:08:07.502: E/AndroidRuntime(24457): at dalvik.system.NativeStart.main(Native Method)
08-10 00:08:07.502: E/AndroidRuntime(24457): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
08-10 00:08:07.502: E/AndroidRuntime(24457): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:228)
08-10 00:08:07.502: E/AndroidRuntime(24457): at android.app.Activity.requestWindowFeature(Activity.java:3144)
08-10 00:08:07.502: E/AndroidRuntime(24457): at com.mittereder.rockpaper.prefs.onCreate(prefs.java:22)
08-10 00:08:07.502: E/AndroidRuntime(24457): at android.app.Activity.performCreate(Activity.java:4531)
08-10 00:08:07.502: E/AndroidRuntime(24457): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
08-10 00:08:07.502: E/AndroidRuntime(24457): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150)
08-10 00:08:07.502: E/AndroidRuntime(24457): ... 11 more
答案 0 :(得分:1)
您已在Android清单中为您的活动设置主题,如下所示......
<activity android:name=".Login" android:theme="@android:style/Theme.NoTitleBar" />
请在编辑后验证您的活动代码。
答案 1 :(得分:0)
试试这个:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
addPreferencesFromResource(R.xml.myPreferences);
}
清单中的:
<activity android:name=".MyPreferencesActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar">