From the course: Complete Guide to Android Development with Kotlin for Beginners
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Load image resources at runtime
From the course: Complete Guide to Android Development with Kotlin for Beginners
Load image resources at runtime
- [Instructor] Currently we're statically setting the Drawable resource. Every time we run the app, the image is going to be the same and it doesn't update. But with the image component, we can load resources at runtime as well. This will allow for the image to change based on user action or a change in data. Let's update our layout so that we can include some interaction from the user. For this, we're going to introduce a switch composable. The first thing we'll need is a variable that will hold the state of the switch. So I'm going to come here to the beginning of our composable function. And then on line number 41, I'm going to create a new variable, which we'll name checked. And this is going to use the remember in line function, we'll be talking more about the remember function later. Next, we're going to have the default value be true. Okay, so by default our switch is going to be in the on state, right? So we have our checked variable. Perfect. Next we're going to add the…
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
Display image resources4m 11s
-
(Locked)
Load image resources at runtime3m 36s
-
(Locked)
Reduce file size with WebP images2m 55s
-
(Locked)
Use XML-based VectorDrawable images3m 55s
-
(Locked)
Create icons in Android Studio2m 58s
-
(Locked)
Challenge: Load a network image1m 55s
-
(Locked)
Solution: Load a network image2m 39s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-