2014-12-19 60 views
3

一個有問題
我想隱藏從活動的標題欄從活動(不包括XML編輯),但總是得到一個錯誤如何隱藏Android應用程序的標題欄?

我試着在幾篇文章中使用建議:
Android title bar removal
How to hide app title in android
Make full screen activity

但它並沒有讓我期待的結果。我做錯了什麼?

IMG:http://i57.tinypic.com/wj6ud4.png

12-19 14:09:21.679  848-848/com.example.switchoff.test_app E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.switchoff.test_app/com.example.switchoff.test_app.MainActivity}: java.lang.NullPointerException 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
      at android.app.ActivityThread.access$600(ActivityThread.java:130) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
      at android.os.Handler.dispatchMessage(Handler.java:99) 
      at android.os.Looper.loop(Looper.java:137) 
      at android.app.ActivityThread.main(ActivityThread.java:4745) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:511) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
      at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.NullPointerException 
      at android.support.v7.internal.app.WindowDecorActionBar.getDecorToolbar(WindowDecorActionBar.java:248) 
      at android.support.v7.internal.app.WindowDecorActionBar.init(WindowDecorActionBar.java:201) 
      at android.support.v7.internal.app.WindowDecorActionBar.<init>(WindowDecorActionBar.java:176) 
      at android.support.v7.app.ActionBarActivityDelegateBase.createSupportActionBar(ActionBarActivityDelegateBase.java:156) 
      at android.support.v7.app.ActionBarActivityDelegate.getSupportActionBar(ActionBarActivityDelegate.java:123) 
      at android.support.v7.app.ActionBarActivityDelegateBase.onTitleChanged(ActionBarActivityDelegateBase.java:467) 
      at android.support.v7.app.ActionBarActivity.onTitleChanged(ActionBarActivity.java:176) 
      at android.app.Activity.onPostCreate(Activity.java:1000) 
      at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1142) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2042) 
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
                at android.app.ActivityThread.access$600(ActivityThread.java:130) 
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
                at android.os.Handler.dispatchMessage(Handler.java:99) 
                at android.os.Looper.loop(Looper.java:137) 
                at android.app.ActivityThread.main(ActivityThread.java:4745) 
                at java.lang.reflect.Method.invokeNative(Native Method) 
                at java.lang.reflect.Method.invoke(Method.java:511) 
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                at dalvik.system.NativeStart.main(Native Method) 

回答

1

您可以使用

getActionBar().hide();

getSupportActionBar().hide();

+0

THX很多!非常簡單的方法! – Nick

+0

很高興我幫助過這個人 –

2

在行爲使用this.requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.yourlayout);

requestWindowFeature(Window.FEATURE_NO_TITLE); 
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
WindowManager.LayoutParams.FLAG_FULLSCREEN); 

或對於ACTIONBAR使用getActionBar().hide();

1

你不用加:

requestWindowFeature(Window.FEATURE_NO_TITLE); 

我剛纔說:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,         
               WindowManager.LayoutParams.FLAG_FULLSCREEN); 
我style.xml

然後,我有如下:

.... 
<style name="AppTheme" parent="android:Theme.Light"> 
    <!-- Customize your theme here. --> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowFullscreen">true</item> 
    <item name="android:screenOrientation">portrait</item> 
    <item name="android:windowBackground">@drawable/logo</item> 
</style> 

,這是爲我工作,希望這可以幫助您太...

0
ActionBar actionBar = getActionBar(); 
actionBar.hide() 
+0

這個答案被標記爲低質量,因爲它的長度和內容。請添加一個簡單的英文解釋。 – Jubobs

相關問題