-1

I can not use bitmap as background of a button on android with kotlin

2 Answers2

0

In Activity:

Button11.setBackgroundColor(getResources().getColor(R.color.red));

When not in Activity:

Button11.setBackgroundColor(Button11.getContext().getResources().getColor(R.color.red));

For full customized color:

Button11.setBackgroundColor(0xFFFF0000);

For setting a bitmap

Button11.setBackground(yourBitmapObject)
VishalJha
  • 131
  • 2
  • 7
  • 1
    This doesn't help set a _bitmap_ as the background, as the question asked for. – Ryan M Jun 18 '20 at 02:10
  • Main question is setting a button background in kotlin also for bitmap it will be still same just they have to pass there bitmap in the parameter. Button.setBackground(bitmap) – VishalJha Jun 18 '20 at 03:41
  • 1
    Your solution in the comments would be a good addition to your answer, and would make it correct, I think. – Ryan M Jun 18 '20 at 03:43
0

Go to you app's layout file. Make sure you are on the Design tab. Click the button and look at it's attributes on the right-hand side. Then click the search icon in the attributes. Type in background on the search bar. You will see a background attribute. Click the Pick a resource button on the right-hand side of the background attribute(it's on the same line). Select your desired background for your button.

Hope it helps :)

Mahir Islam
  • 1,941
  • 2
  • 12
  • 33