简体   繁体   English

如何隐藏Android应用程序的标题栏?

[英]How to hide the title bar for of android app?

A have a problem 有问题
I want to hide title bar from activity from activity (without xml editing), but always get an error 我想从活动中隐藏标题栏(没有xml编辑),但总是会出错

I tried to use advices in few articles: 我试着在几篇文章中使用建议:
Android title bar removal Android标题栏删除
How to hide app title in android 如何在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 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)

In Activity Use this.requestWindowFeature(Window.FEATURE_NO_TITLE); 在Activity中使用this.requestWindowFeature(Window.FEATURE_NO_TITLE); before setContentView(R.layout.yourlayout); setContentView(R.layout.yourlayout);之前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(); 或者对于ACTIONBAR使用getActionBar().hide();

You can use 您可以使用

getActionBar().hide();

or getSupportActionBar().hide(); getSupportActionBar().hide();

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

this is working for me, hopes this helps you too... 这对我有用,希望这对你有帮助......

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM