2017-10-04 160 views
0

我試圖隱藏整個應用程序的狀態欄,以便它可以真正在全屏幕中工作,但事情是當用戶最小化應用程序或按主頁按鈕,然後打開應用程序狀態欄再次出現,並且不會消失,用戶最小化應用後狀態欄回來(Android Studio)

此外,當應用程序在第一次運行時打開時,隱藏狀態欄(3秒)會有一些滯後時間,然後它會消失變白

我的應用程序只有兩個活動,我希望應用程序隱藏兩個活動

我的主要活性狀況狀態欄TY的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(); 
 
    } 
 

 
}

回答

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" > 
+0

非常感謝工作像魅力的男人........... – devdreamer

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

</style 
+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()