How do I hide the title bar of an Android app?

A have problem I want to hide title bar from activity from activity (no xml editing) but always get error

I've tried to follow the tips in several articles:
Removing the Android title bar
How to hide the application title in android
Make a full screen activity

But this did not lead me to the expected result. What am I doing wrong?

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)

      

+3


source to share


4 answers


you can use

getActionBar().hide();



or getSupportActionBar().hide();

+1


source


In action Use this.requestWindowFeature(Window.FEATURE_NO_TITLE);

before setContentView(R.layout.yourlayout);

or

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

      



or For ACTIONBAR

UsegetActionBar().hide();

+2


source


you don't need to add:

requestWindowFeature(Window.FEATURE_NO_TITLE);

      

I just added:

  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                                
                                               WindowManager.LayoutParams.FLAG_FULLSCREEN);

      

Then in my style .xml, I am below:

....
<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>

      

this works for me, hopes it helps too ...

+1


source


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

      

0


source







All Articles