1

I have a resource png of a house linked if you want to view it. It's basically just a dark home button.

I have it included and imported as an image asset as a drawable.

I'm attempting to set it as a button, but change it to be a white color programmatically.

Here's how I'm attempting to change the color to be white:

 ImageButton txtbtnAccept = new ImageButton(this); this._surveyHomeButton = txtbtnAccept; txtbtnAccept.setId(this.generateViewId()); txtbtnAccept.setLayoutParams(new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); layoutParams = (RelativeLayout.LayoutParams) txtbtnAccept.getLayoutParams(); layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); layoutParams.height = 200; layoutParams.width = 200; txtbtnAccept.setScaleType(ImageView.ScaleType.FIT_CENTER); txtbtnAccept.setAdjustViewBounds(true); txtbtnAccept.setLayoutParams(layoutParams); txtbtnAccept.setBackgroundResource(0); txtbtnAccept.setVisibility(View.GONE); Bitmap homeImage = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_home); Drawable whiteImg = new BitmapDrawable(getResources(), homeImage); whiteImg.setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY); txtbtnAccept.setImageDrawable(whiteImg); txtbtnAccept.setImageBitmap(homeImage); 

Any idea where I'm going wrong?

1 Answer 1

2

What you want is called tinting. Have a look at DrawableCompat.setTint(Drawable, int).

Sign up to request clarification or add additional context in comments.

1 Comment

Led me down the right path - I ended up using an example here - stackoverflow.com/questions/20121938/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.