Defined custom shape for button in xml. Now I want to change the color dynamically. How?

前端 未结 3 891
情书的邮戳
情书的邮戳 2020-12-11 12:26

I have this:

round_button.xml




        
3条回答
  •  不知归路
    2020-12-11 13:13

    I solved it by setting a ColorFilter:

    Drawable mDrawable = context.getResources().getDrawable(R.drawable.balloons); 
    mDrawable.setColorFilter(new PorterDuffColorFilter(0xffff00,PorterDuff.Mode.MULTIPLY));
    myButton.setResource(mDrawable);
    

提交回复
热议问题