From the course: Android Development Essential Training: Manage Data with Kotlin

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Add a dynamic background to data items

Add a dynamic background to data items

From the course: Android Development Essential Training: Manage Data with Kotlin

Start my 1-month free trial

Add a dynamic background to data items

- Recycler view lists and grids are frequently used to create a selectable interface, that is, a list of data items that the user can choose from. The recycler view doesn't automatically give the user a visual indication of selection status though, that's up to you. In order to implement a selectable color, you must create your own files. You could use simple colors as backgrounds, but you can create a more interesting appearance with xml based drawable and shape files. I'll start in this example by creating a new drawable file. In the project window, I'll right click on the drawable directory, and choose New, Drawable Resource File. Then I'll call it background. Now my first job will be to create a shape. The shape will have a fill, a color that is, and it'll have a border. I'll change this file's root element name to shape, then within that I'll add a solid child element, and I'll set the color attribute to pound f-f-f. This is going to be the default background color, it'll be…

Contents