用户最小化应用程序(Android Studio)后,状态栏会回来

时间:2017-10-04 10:58:03

标签: javascript java android

我正在尝试隐藏整个应用程序的状态栏,以便它可以真正在全屏工作,但事情是,当用户最小化应用程序或按主页按钮,然后打开应用程序状态栏重新出现和不会消失,

此外,当应用程序在首次运行时打开时,隐藏状态栏会有一些延迟时间(3秒),然后它就会变为白色

我的应用只有两个活动,我希望应用隐藏两个活动的状态栏

我的主要活动java

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

    private ProgressDialog pd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        View decorView = getWindow().getDecorView();
        // Hide the status bar.
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);

        WebView webView = new WebView(this);
        webView.setClickable(true);
        webView.setFocusableInTouchMode(true);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://www.notherstore.in");
        WebClientClass webViewClient = new WebClientClass();
        webView.setWebViewClient(webViewClient);

        setContentView(webView);
        pd = new ProgressDialog(MainActivity.this);
        pd.setTitle("Loading Store");
        pd.setMessage("This may take several Minutes...");
        pd.show();
    }

    public class WebClientClass extends WebViewClient {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);


        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            pd.dismiss();
        }
    }

}

我的启动画面活动java

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;


public class SplashScreen extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        View decorView = getWindow().getDecorView();
// Hide the status bar.
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);

        setContentView(R.layout.splash);

        Thread timerThread = new Thread(){
            public void run(){
                try{
                    sleep(3000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }finally{
                    Intent intent = new Intent(SplashScreen.this,MainActivity.class);
                    startActivity(intent);
                }
            }
        };
        timerThread.start();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        finish();
    }

}

2 个答案:

答案 0 :(得分:1)

尝试添加以下标志

getWindow().getDecorView().setSystemUiVisibility(
  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

和清单中的全屏主题

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

答案 1 :(得分:0)

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

编辑:

如果您正在使用AppCompatActivity,则需要将主题设置如下

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.AppCompat.Light.NoActionBar"/>

如果你想动态地做,那么试着继续OnResume()