Search code examples
androidkotlindrawable

Kotlin Emulator does not run app when as use a png image as drawable


I'm using Android Studio Dolphin | 2021.3.1 and Pixel 5 API emulator.

The following code is used to show image in a button.

But when I use calc.png emulator says launch is successful but quit from application.

If I use xml image as source it works fine.


Icon(imageVector = ImageVector.vectorResource(
   id = R.drawable.calc),
   modifier = Modifier.size(buttonWidth),
   contentDescription = "drawable icons",
   tint = Color.Unspecified
)

Solution

  • When painter has been used it is worked.

            Icon(
                        painter = painterResource(R.drawable.calc),
                        modifier = Modifier.size(buttonWidth),
                        contentDescription = "drawable icons",
                        tint = Color.Unspecified
                    )