2017-07-31 7 views
0

私はカスタムdrawable shapeソリッドカラーランタイムをプログラム的に変更したいのですが、ソリッドカラーをどのように変更できますか?プログラムでランタイムからカスタムドロアブルのソリッドカラーを変更しますか?

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:id="@+id/gradientDrawble" 
     > 
     <selector> 
      <item 
       android:state_selected="true" 
       > 
       <shape 
        android:shape="oval"> 
        <solid 
         android:color="@color/colorCrownCandy"/> 
       </shape> 
      </item> 

      <item > 
       <shape 
        android:shape="oval"> 
        <padding 
         android:bottom="10dp" 
         android:left="10dp" 
         android:right="10dp" 
         android:top="10dp"/> 
        <solid 
         android:color="@color/colorCrownCandy" 
         /> 
       </shape> 
      </item> 
     </selector> 

    </item> 
    <item android:drawable="@drawable/ic_homemenu" 
     /> 
</layer-list> 
+0

@Abhiをすべてがちょうど必要な変更の色 – Mahesh

+0

[this](https://stackoverflow.com/a/39364523/5015207)多分役立つでしょうか? – 0X0nosugar

答えて

0

このお試しください:はい、それはcolor.xmlから色ですが、私はその固体の色を変更したいので、私はこれだけ1描画可能な作業に多くの色とドロウアブルの異なる種類を持って

// The "view" is the one for which you are applying the drawable as background. 

GradientDrawable backgroundForShape= (GradientDrawable)view.getBackground(); 
backgroundForShape.setColor(COLOR.RED); 

// You can specify the color you want. The color defines in colors.xml 
backgroundForShape.setColor(ContextCompat.getColor(context, R.color.yourColor)); 
関連する問題