2015-10-25 92 views
-1

這是我在StackOverflow上的第一個問題。我正在開發一個簡單的應用程序,它只有一個帶有進度條的WebView。目前爲止都很好,但是當我的應用程序啓動時,電池狀態和時鐘所在的狀態欄變成了白色。當應用程序啓動時,狀態欄變成白色

我使用過Android Studio 1.4,我對我的Nexus 5,其具有的Android 6.0

我的minSdkVersion是19和targetSdkVersion和compileSdkVersion是23

這裏測試的應用程序是我activity_main.xml中文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_gravity="center_horizontal|top" 
android:fitsSystemWindows="true"> 

<ProgressBar 
style="?android:attr/progressBarStyleHorizontal" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:id="@+id/progressBar" /> 

<WebView 
android:layout_width="match_parent" 
android:layout_height="fill_parent" 
android:id="@+id/android_web_view" /> 

</LinearLayout> 

style.xml

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 
    <style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

</resources> 

,最後MainActivity類: 包haber.plus.haberplus;

import android.app.Activity; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.view.View; 
import android.webkit.WebChromeClient; 
import android.webkit.WebSettings; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 
import android.widget.ProgressBar; 

public class MainActivity extends Activity { 
    private ProgressBar mProgressBar; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     mProgressBar = (ProgressBar) findViewById(R.id.progressBar); 
     final WebView mWebView = (WebView) findViewById(R.id.android_web_view); 

     // Her zaman önbelleği yenile. 
     mWebView.clearCache(true); 

     WebSettings webSettings = mWebView.getSettings(); 
     webSettings.setJavaScriptEnabled(true); 

     mWebView.loadUrl("http://google.com/"); 

     mWebView.setWebChromeClient(new WebChromeClient() { 
      @Override 
      public void onProgressChanged(WebView view, int newProgress) { 
       super.onProgressChanged(view, newProgress); 

       mProgressBar.setProgress(newProgress); 
      } 
     }); 

     mWebView.setWebViewClient(new WebViewClient(){ 
      @Override 
      public boolean shouldOverrideUrlLoading(WebView view, String url) { 
       view.loadUrl(url); 
       return false; 
      } 
     }); 
    } 
} 

Click here對於描述問題的圖像。

+0

您的styles.xml和MainActtivity類請 –

+0

@MradMrad更新了問題.. –

+0

檢查您的style.xml內的值-V21文件夾。有可能是這條線: @ android:color/holo_red_dark ycagri

回答

0

似乎你的進度條與狀態欄重疊,即使很難看到你的照片上發生了什麼。

你的佈局應該沒有問題 android:layout_gravity="center_horizontal|top" android:fitsSystemWindows="true",所以試試沒有。

+0

它發生在我刪除進度條時。所以我認爲這裏的問題不是進度條。我還刪除了你剛纔告訴我的其他內容,但沒有奏效。 –

+0

通常,您可以通過將自定義主題分配給應用程序來更改狀態欄的顏色。轉到RES /價值/的themes.xml和類似 ' <樣式名稱= 「Theme.MyTheme」 父= 「Theme.AppCompat.Light」> <項目名稱= 「colorPrimaryDark」>寫#00000 '。 'colorPrimaryDark'還定義了狀態欄的顏色,這裏是黑色(#00000)。然後,您需要將該自定義主題設置爲您的應用程序:在您的AndroidManifest.xml中爲''標籤添加'android:theme =「@ style/Theme.MyTheme」'。 – dabo

+0

謝謝。創造我自己的主題運作良好。 –

相關問題