2016-02-05 99 views
-1

我在我的應用程序中製作了Splash Screen。我必須在我的啓動畫面中設置ProgressBar。但ProgressBar顯示綠色,我必須設置白色使用代碼但它工作後一段時間。首先它顯示綠色然後它變成白色Android Splash Screen ProgressBar顏色不變

創建ProgressBar我已使用此https://github.com/rahatarmanahmed/CircularProgressView 任何幫助被讚賞。

Java代碼:

public class SplashScreenActivity extends Activity { 

    // Set Duration of the Splash Screen 

    CircularProgressView progressView; 
    private static int SPLASH_TIME_OUT = 3000; 

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

     // Remove the Title Bar 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 

     // Get the view from splash_screen.xml 
     setContentView(R.layout.splash_screen); 


     new Handler().postDelayed(new Runnable() { 


      @Override 
      public void run() { 

       progressView = (CircularProgressView) findViewById(R.id.progress_view); 
       progressView.setColor(Color.parseColor("#FFFFFF")); 



       finish(); 
       Intent myIntent = new Intent(SplashScreenActivity.this, 
         MainActivity.class); 
       startActivity(myIntent); 
      } 
     }, SPLASH_TIME_OUT); 


    } 
} 
+0

能否請你加上你的代碼是如何以身作則向上?這將使得提供一些幫助變得更容易。看起來有一些線程問題。 – jaolstad

+0

你可以分享你的代碼,並請突出顯示它出錯的地方。 –

+0

@ destination-data我已經添加了代碼,並且以自己的方式讓它不使用任何示例。 – Harshad

回答

0

更改代碼的替代方案,將工作完全把進度intialization和的setColor屬性之前的處理程序代碼看代碼後:

public class SplashScreenActivity extends Activity { 

    // Set Duration of the Splash Screen 

    CircularProgressView progressView; 
    private static int SPLASH_TIME_OUT = 3000; 

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

     // Remove the Title Bar 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 

     // Get the view from splash_screen.xml 
     setContentView(R.layout.splash_screen); 

    progressView = (CircularProgressView) findViewById(R.id.progress_view); 
        progressView.setColor(Color.parseColor("#FFFFFF")); 

     new Handler().postDelayed(new Runnable() { 

      @Override 
      public void run() { 

       finish(); 
       Intent myIntent = new Intent(SplashScreenActivity.this, 
         MainActivity.class); 
       startActivity(myIntent); 
      } 
     }, SPLASH_TIME_OUT); 


    } 
} 
0

試試這個代碼,它會工作。

new Handler().postDelayed(new Runnable() { 


      @Override 
      public void run() { 

       progressView = (CircularProgressView) findViewById(R.id.progress_view); 
       progressView.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.accent_dark), 
         PorterDuff.Mode.SRC_IN); 



       finish(); 
       Intent myIntent = new Intent(SplashScreenActivity.this, 
         MainActivity.class); 
       startActivity(myIntent); 
      } 
     }, SPLASH_TIME_OUT); 
+0

使用此代碼我有兩個問題。 1.無法解析符號getIndeterminateDrawable 2. getColor已棄用。 – Harshad

+0

@Harshad您正在使用自定義視圖?你使用的是,你可以很容易地得到這個代碼的循環進度條。 <進度 風格= 「機器人:ATTR/progressBarStyle」 的android:layout_width = 「WRAP_CONTENT」 機器人:layout_height = 「WRAP_CONTENT」 機器人:ID = 「@ + ID/splash_progressBar」/> 再申請使用新方法的顏色(在棄用之後)。 – androidnoobdev

+0

我的ProgressBar可以在其他活動中正常工作,但不能在Splash Screen中工作我不知道什麼是問題。我認爲這是線程問題。和其他解決方案,所以它幫助我。 – Harshad