I can not use bitmap as background of a button on android with kotlin
Asked
Active
Viewed 177 times
-1
-
1Check out this -- https://android.jlelse.eu/android-shape-drawables-tutorial-17fbece6fef5 Also this post -- https://stackoverflow.com/questions/34235742/specify-buttons-background-shape-color-outside-of-the-backgrounds-xml – Anuj Sharma Jun 13 '20 at 12:18
-
Post your code pls – Gabriele Mariotti Jun 13 '20 at 12:28
2 Answers
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
-
1This 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
-
1Your 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