简体   繁体   English

如何隐藏状态栏-Android

[英]How to hide status bar - Android

I am trying to hide status bar but it is not working for me. 我正在尝试隐藏状态栏,但它对我不起作用。

I tried to add 我试图添加

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

In AndroidManifest.xml But it is not working. 在AndroidManifest.xml中,但是它不起作用。

I also tried to add 我也尝试添加

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

In onCreate function 在onCreate函数中

But nothing is working. 但是没有任何效果。 I am using phonegap build. 我正在使用phonegap构建。 First time when i open my application status bar goes away but after 1 sec it comes back. 第一次打开应用程序状态栏时,它消失了,但是1秒钟后又回来了。

在此处输入图片说明

Can anyone help me? 谁能帮我?


I fix it. 我修理它。 In onCreate function i add this lines 在onCreate函数中,我添加以下行

this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

Now status bar is hidden... 现在状态栏已隐藏...

Oficial way: https://developer.android.com/training/system-ui/status.html 官方方式: https//developer.android.com/training/system-ui/status.html

And you can try this: 您可以尝试以下操作:

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

Try that. 试试看 You can check here: How to hide status bar in Android 您可以在此处查看: 如何在Android中隐藏状态栏

You can do it by two ways 您可以通过两种方式做到这一点

1) Programatically : 1)以编程方式:

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class ActivityName extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // remove title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}

2) Modifying AndroidManifest.xml file: 2)修改AndroidManifest.xml文件:

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>

只需关闭省电模式即可。

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

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