Join Chiu-Ki Chan for an in-depth discussion in this video Vector drawable: Create, part of Effective Android Testing for Mobile Developers.
- [Instructor] The last feature we are adding to our app is favorites. We want to be able to mark our favorite recipe with a star, and we want the app to remember it. First, let's create the star graphic. We will use vector drawable. So let's go to app slash build.gradle and add the perimeter for it. Click on build.gradle, and then at the top, after version name at line 11, add the perimeter VectorDrawables.useSupportLibrary.
Set it to true. Press sync now to do a gradle sync. This means that we want to be able to use vector drawables for devices that don't support it natively by using the Support Library. Next we will create our vector drawable. Right click on the res folder, New, Vector Asset. Click on the icon. Select toggle, the last item on the left. Choose the solid star with the name star.
Press okay. We'll rename it to ic_favorite_solid. Press next, and press finish. We're going to do this again to make the hollow one. So res, New, Vector Asset. Click on icon, toggle, star border. Change the name to favorite_hollow. Click next and finish.
We have two drawables. One for when the recipe is favorited, and one when it's not. We're going to tie them together in an XML file that has state so that we can have it as selected, or not selected. Click on drawable under res, right click, New, Drawable resource file. We are going to call it ic_favorite, and we'll leave the root element as selector. Inside the selector, we are going to have two items.
Item android:drawable. We are going to choose the solid one for the selector stay. So @drawable/ic_favorite_solid. We want to use the solid star when the recipe is selected. So let's specify android:state_selected and set it to true. We will also need to have a base case when it is not selected. Press Command + D to duplicate this line.
Change ic_favorite_solid to hollow and delete the selected line. This means whenever the first condition is not met, the hollow graphic will be shown. Next, we are going to take this vector drawable and use it in the recipe activity.
- Why test?
- Local vs. on-device
- Code coverage
- UI testing
- Hermetic environment
- Dependency injection
- Testing with MVP
Skill Level Intermediate
Android App Development: Unit Testingwith James P White2h 58m Intermediate
Android Studio Essential Trainingwith David Gassner3h 41m Beginner
Android App Development: Data Persistence Librarieswith Annyce Davis3h 59m Intermediate
1. Testing Considerations
2. Test as You Go
3. UI Testing
4. Hermetic Environment
5. Robot Pattern
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.