drawables,*and*styles,*and*android.r*cs5957/media/murdock 8... · drawables* •...

18
Drawables, and Styles, and android.R Oh my!

Upload: others

Post on 11-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

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”*

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”*

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”*

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”*

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”*

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”*

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”*

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”*

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”*

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”*

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”*

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”*

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”*

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”*

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”*

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”*

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”*

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”*

QuesPons?