Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* •...
Transcript of Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* •...
![Page 1: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/1.jpg)
Drawables, and Styles, and android.R
Oh my!
![Page 2: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/2.jpg)
Drawables
• Generic class for drawing content to the screen
• Can represent image resources and “shapes” • Can be combined and modified via XML to make complex resources
• Easier than subclassing
• hIp://developer.android.com/guide/topics/resources/drawable-‐resource.html
![Page 3: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/3.jpg)
Drawables
• Bitmap • XML Bitmap • Nine-‐patch • Layer List • State List • Level List • TransiPon
• Inset • Clip • Scale • Shape
![Page 4: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/4.jpg)
XML Bitmap
• Refers to a bitmap resource • Defines filter and scaling rules
![Page 5: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/5.jpg)
Nine-‐Patch
• PNG with extra pixels to define stretchable regions and content bounds
• hIp://radleymarx.com/blog/simple-‐guide-‐to-‐9-‐patch/
![Page 6: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/6.jpg)
Shape
• Define a shape, its fill/stroke, color/gradient • Rect, Oval, Line, Ring
![Page 7: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/7.jpg)
Shape
![Page 8: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/8.jpg)
Layer List
• Combines mulPple drawables into a single drawable resource.
• Drawn in order, last on top. • Can be used to add simple effects to exisPng drawables.
![Page 9: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/9.jpg)
State List
• Specifies a set of drawables for different view states.
• Pressed, Enabled, Selected…. • Very useful for buIons (up and down state)
![Page 10: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/10.jpg)
Level List
• Specifies a set of drawables displayed according to a level value.
• Use LevelListDrawable.setLevel(…) to change image.
• Great for 3 state switches.
![Page 11: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/11.jpg)
Others
• TransiPon • Inset • Clip • Scale • See documentaPon at: hIp://developer.android.com/guide/topics/resources/drawable-‐resource.html
![Page 12: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/12.jpg)
Combine and Save!
• Most of these can be used in combinaPon. • Use a smaller set of base images to build out all resources.
• Use shapes instead of images if possible. Takes up less space, scales beIer.
![Page 13: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/13.jpg)
Styles
• Inspired by CSS • Lets you define sets of aIributes for views • Reusable, extensible, maintainable • Dynamic like drawables and layouts • DRY
![Page 14: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/14.jpg)
Styles
![Page 15: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/15.jpg)
Themes
• Themes are styles set on the AcPvity or ApplicaPon (in the manifest).
• Overrides default values for Views in the AcPvity/AppliaPon.
• Separates the design from the content.
![Page 16: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/16.jpg)
Extending Styles
• Styles can inherit from one another. • Makes it easy to make small changes to exisPng styles.
![Page 17: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/17.jpg)
android.R
• Resources provided by SDK • Contains many things including simple layouts, and default icons.
• In XML accessed as @android:<type>/<name> • Defines standard themes such as Holo or the “Ice Cream Sandwich” theme
![Page 18: Drawables,*and*Styles,*and*android.R*cs5957/media/Murdock 8... · Drawables* • Generic*class*for*drawing*contentto*the* screen • Can*representimage*resources*and*“shapes”*](https://reader034.fdocuments.net/reader034/viewer/2022043019/5f3ba26f8efd07358401ca3c/html5/thumbnails/18.jpg)
QuesPons?