A有问题 我想从活动中隐藏标题栏(没有xml编辑),但总是出错
我试着在几篇文章中使用建议:
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)
答案 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 :(得分:1)
您可以使用
getActionBar().hide();
或
getSupportActionBar().hide();
答案 2 :(得分: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>
这对我有用,希望这对你有帮助......
答案 3 :(得分:0)
ActionBar actionBar = getActionBar();
actionBar.hide()