2017-06-09 85 views
0

我想在更改進度時更改android中的搜索欄顏色。在下面的圖片中,1-2的藍色,2-3的綠色等等。可能嗎? 到目前爲止,我的代碼是;在Android中更改搜索欄顏色的時間間隔

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

     SeekBar seekBar = (SeekBar)findViewById(R.id.seekbar); 
     seekBar.setProgress(0); 
     seekBar.incrementProgressBy(10); 
     seekBar.setMax(200); 
     seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){ 
      @Override 
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 
       progress = progress/10; 
       progress = progress * 10; 
        int stepSize = 25; 
        progress = (progress/stepSize)*stepSize; 
        seekBar.setProgress(progress); 
      } 

      @Override 
      public void onStartTrackingTouch(SeekBar seekBar) { 

      } 

      @Override 
      public void onStopTrackingTouch(SeekBar seekBar) { 

      } 
     }); 
    } 

enter image description here

回答

0
progress.xml 
---------- 
<?xml version="1.0" encoding="utf-8"?> 
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
     <item 
      android:id="@android:id/background" 
      android:drawable="@drawable/background_fill" /> 

     <item android:id="@android:id/progress"> 
      <clip android:drawable="@drawable/progress_fill" /> 
     </item> 
    </layer-list> 
background_fill.xml 
---------- 


<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
     <gradient 
      android:startColor="#FF555555" 
      android:centerColor="#FF555555" 
      android:endColor="#FF555555" 
      android:angle="90" /> 

     <corners android:radius="5px" /> 

     <stroke 
      android:width="2dp" 
      android:color="#50999999" /> 

     <stroke 
      android:width="1dp" 
      android:color="#70555555" /> 
    </shape> 

---------- 
progress_fill.xml 

<?xml version="1.0" encoding="UTF-8"?> 
     <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
      <gradient 
       android:startColor="#FF470000" 
       android:centerColor="#FFB80000" 
       android:endColor="#FFFF4400" 
       android:angle="180" /> 

      <corners android:radius="5px" /> 

      <stroke 
        android:width="2dp" 
        android:color="#50999999" /> 

      <stroke 
        android:width="1dp" 
        android:color="#70555555" /> 
     </shape> 
---------- 


In xml where You write seekabr code add this 



android:thumb="@drawable/thumb" 

I hope this code is help to solve Your Problem. 
Do You have idea How can you add These Files in Your Project 
+0

我在這一行'Android上得到錯誤:拇指= 「@繪製/拇指」'。名稱縮略圖中沒有任何可繪製文件。我添加了其他文件和代碼'後臺進度等 – Amar