2016-10-20 1 views
0

indeterminate progress barどのように私はAPIレベル14をサポートするAndroidの中に無限のプログレスバーの前景色を変更し、

の上に私はAndroidのプログレスバーの前景色(青)を変更したいことができ、動的にCOLOR_DEFINED .Butに保ちますバックグラウンドカラー(グレイ)そのままです。システムの最小APIレベルは14です。同じようにする方法を見つけることができません。

同じ背景色とCOLOR_DEFINEDのColorFilterを作成しようとすると、その上にオーバーレイされます。

私は既にPorterDuff.Modeを試しましたが、どれもうまく動作しません。

答えて

0

しばらくの間、試してみてください。

水平プログレスバーindeterminateDrawable 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"> 
     <shape> 
      <corners android:radius="2dip" /> 
      <gradient 
       android:startColor="@color/background_grey" 
       android:endColor="@color/light_grey" 
       android:angle="270" 
       /> 
     </shape> 
    </item> 
    <item 
     android:id="@android:id/progress" 
     > 
     <clip> 
      <shape> 
       <corners 
        android:radius="2dip" /> 
       <gradient 
        android:startColor="@color/blue" 
        android:endColor="@color/blue" 
        android:angle="270" /> 
      </shape> 
     </clip> 
    </item> 
</layer-list> 

コード:

プログレスたpB =(プログレス)v.findViewById(R.id.activation_progressBar)。

if (pB != null) { 

     if (pB.getIndeterminateDrawable() != null) { 

      //Getting the progress element from the indeterminate progress drawable and setting it to the custom color specified. 
      final LayerDrawable indeterminateDrawable = (LayerDrawable) pB.getIndeterminateDrawable(); 
      indeterminateDrawable.getDrawable(1).setColorFilter(CUSTOM_DEFINED, PorterDuff.Mode.SRC_IN); 
     } 
    } 
関連する問題