Reputation: 35
A have a problem
I want to hide title bar from activity from activity (without xml editing), but always get an error
I tried to use advices in few articles:
Android title bar removal
How to hide app title in android
Make full screen activity
But it isn't led me to expected result. What i'm 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)
Upvotes: 3
Views: 957
Reputation: 4284
you need not add :
requestWindowFeature(Window.FEATURE_NO_TITLE);
I have just added :
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Then in my style.xml, I have 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 is working for me, hopes this helps you too...
Upvotes: 3
Reputation: 5707
In Activity 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
Use getActionBar().hide();
Upvotes: 2
Reputation: 3260
You can use
getActionBar().hide();
or
getSupportActionBar().hide();
Upvotes: 1