2012-08-10 107 views
0

我試圖隱藏我的偏好設置屏幕的標題欄中的標題欄,但通常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> 

的Java:

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

您可能會錯過 「>」 或 「/>」 中的活動標籤,同時ü編輯它。請驗證它... :) – 2012-08-10 04:13:17

+0

?我認爲它只是選中了一點:) – 2012-08-10 04:14:13

+0

欲瞭解更多信息,請查看此鏈接。 http://stackoverflow.com/questions/2591036/how-to-hide-the-title-bar-for-an-activity-in-xml-with-existing-custom-theme/2591311#2591311 – 2012-08-10 04:23:43

回答

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"> 
+0

我試過了,我的應用程序崩潰了,我發佈logcat在我的編輯 – 2012-08-10 04:09:22

+0

發佈日誌時,應用程序崩潰 – 2012-08-10 04:10:47

+0

發佈它在我的編輯上面 – 2012-08-10 04:12:02

1

已設置的主題爲android系統中的活動表現如下...

<activity android:name=".Login" android:theme="@android:style/Theme.NoTitleBar" /> 

請在編輯它之後驗證您的活動標記。

+0

我把android:theme =「@ android:style/Theme.Light.NoTitleBar」就像一個魅力<3謝謝! – 2012-08-10 04:31:26