如何隐藏状态栏?

时间:2015-11-14 06:16:33

标签: android android-activity android-statusbar

如何隐藏特定活动的状态栏?

我发现了类似的问题,但没有一个答案适合我。每次我尝试去参加活动时应用程序都崩溃了: How to hide status bar in Android

感谢。

5 个答案:

答案 0 :(得分:19)

在设置内容之前,请在您的活动中尝试此操作

{{1}}

答案 1 :(得分:3)

隐藏Android 4.0及更低版本的状态栏

  1. 通过在manifest.xml文件中设置应用程序的主题。

    android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
    

    或者

  2. 通过在活动的onCreate()方法中编写JAVA代码。

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // If the Android version is lower than Jellybean, use this call to hide
        // the status bar.
        if (Build.VERSION.SDK_INT < 16) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        setContentView(R.layout.activity_main);
    }
    
  3. 隐藏Android 4.1及更高版本上的状态栏

    通过在Activity的onCreate()方法中编写JAVA代码。

    View decorView = getWindow().getDecorView();
    // Hide the status bar.
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
    // Remember that you should never show the action bar if the
    // status bar is hidden, so hide that too if necessary.
    ActionBar actionBar = getActionBar();
    actionBar.hide();
    

答案 2 :(得分:1)

if (Build.VERSION.SDK_INT < 16)//before Jelly Bean Versions
{ 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                         WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else // Jelly Bean and up
{ 
    View decorView = getWindow().getDecorView();
    // Hide the status bar.
    int ui = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(ui);

    //Hide actionbar
    ActionBar actionBar = getActionBar();
    actionBar.hide();
}

答案 3 :(得分:0)

打开styles.xml并更新您的活动使用的样式:

<style name="ExampleTheme" parent="android:Theme.Light">
    <item name="android:windowNoTitle">true</item> <!-- add this line -->
</style>

答案 4 :(得分:0)

唯一有效的答案(至少对我来说)

在styles.xml中

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        ...
    </style>
</resources>

在4.4.2 Kitkat中,代码内解决方案不适用于我。

相关问题