Developers

Android Design for UI Developers 13

+Roman Nurik

+Nick Butcher

Android Design in Action www.androiddesigninaction.com

4

Agenda App Navigation

Responsive Design

Holo Visual Language

Lateral navigation

Why responsive

Dividers and borderless buttons

Navigation drawers

Responsive strategies

List headings

Up navigation

Fragments

Typography

Resource framework

Full-bleed images Generating assets

5

App Navigation

Action bar tabs and spinner

7

COMIN

ActionBarCompat

G SOO

N

Native API

ActionBarCompat

Activity or FragmentActivity

ActionBarActivity

getActionBar()

getSupportActionBar()

Theme.Holo Widget.Holo...

Theme.AppCompat Widget.AppCompat...

android:actionBarStyle android:displayOptions

actionBarStyle (no prefix) displayOptions (no prefix)

android:showAsAction

yourAppNamespace:showAsAction

Android 2.1+ (99.9% of devices)

Alternatively, continue using Jake Wharton’s incredible ActionBarSherlock library

8

ViewPager

9

Navigation drawers Primarily for main app navigation Only for 3+ top level views of disparate, mutually exclusive content More at d.android.com/design

10

Navigation drawers 11

ActionBarDrawerToggle and DrawerListener // ActionBarDrawerToggle provides convenient helpers // for tying together the prescribed interactions // between a top-level sliding drawer and the action bar. mDrawerToggle = new ActionBarDrawerToggle( this, /* activity */ mDrawerLayout, R.drawable.ic_drawer, /* download available */ R.string.drawer_open, /* content descriptions */ R.string.drawer_close) { public void onDrawerClosed(View view) { // Set the action bar title to the content title. getActionBar().setTitle(mTitle); }

DRAWER CLOSED

DRAWER OPEN

public void onDrawerOpened(View drawerView) { getActionBar().setTitle(“Navigation Drawer Example”); }

}; mDrawerLayout.setDrawerListener(mDrawerToggle);

12

ActionBarDrawerToggle

@Override public boolean onOptionsItemSelected(MenuItem item) { /* * The action bar home/up action should open or * close the drawer. * ActionBarDrawerToggle will take care of this. */ if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); }

DRAWER CLOSED

DRAWER OPEN

13

Up navigation showHome|homeAsUp|showTitle



14

Custom Up navigation @Override public Intent getParentActivityIntent() { // Used when navigating within the same task. return new Intent(this, MyParentActivity.class) .putExtra(START_TAB, 2); } @Override public void onCreateNavigateUpTaskStack(TaskStackBuilder builder) { // Used when synthesizing the stack in a new task. builder.addNextIntent(new Intent(this, HomeActivity.class)) .addNextIntent(getParentActivityIntent()); }

15

Responsive Design

Device variety

17

Why responsive?

18

Why responsive?

WARN ING

android:layout_width="match_parent"

19

Why responsive?

Why responsive?

21

Combination

22

Fragments

A

B

A

B

23

Alternate layouts

res/layout/activity_home.xml

res/layout/activity_detail.xml

24

Alternate layouts res/layout-w600dp/activity_home.xml

25

Master/Detail Flow template File > New > Android Object

26

SlidingPaneLayout

27

SlidingPaneLayout 28

SlidingPaneLayout

If combined pane widths exceed screen width then right pane overlaps

29

SlidingPaneLayout

Grow to consume available space

30

Macro reflow

31

Alternate layouts res/layout/activity_home.xml

res/layout-land/activity_home.xml







32

Micro reflow

33

Dimension files res/values/dimens.xml

page_margin

… 16dp 18sp …

headline_text_size body_text_size body_line_spacing

res/values-sw720dp/dimens.xml … 32dp 22sp …

34

Dimension files res/values/dimens.xml

page_margin

… 16dp 18sp …

headline_text_size body_text_size body_line_spacing

res/values-sw720dp/dimens.xml … 32dp 22sp …

35

Margin point

36

Margin point res/layout/activity_home.xml res/values/styles.xml match_parent res/values-w600dp/styles.xml 600dp center_horizontal 37

Lists to grids

38

Lists to grids res/layout/activity_home.xml res/values/integers.xml 1 res/values-w500dp/integers.xml 2

39

Lists to grids MyAdapter#getView if (convertView == null) { int numColumns = getResources().getInteger(R.integer.num_columns); if (numColumns == 1) { convertView = inflater.inflate(R.layout.list_item_layout, parent, false); } else { convertView = inflater.inflate(R.layout.grid_item_layout, parent, false); } }

40

Responsive design

41

Holo Visual Language

Style Hierarchy res/values/styles.xml

res/values-v11/styles.xml

43

Style Hierarchy res/values/styles.xml

res/values-v11/styles.xml

res/values/styles.xml

COMIN



G SOO

N

44

Built-in framework resources Java: android.R.attr.foo

Example dimension resources:

XML: ?android:foo or ?android:attr/foo

?android:actionBarSize ?android:listPreferredItemHeight(Small) ?android:listPreferredItemPaddingLeft

Example style resources:

Example drawable resources:

?android:progressBarStyleLarge

?android:listChoiceIndicatorSingle

?android:borderlessButtonStyle

?android:dividerHorizontal

?android:listSeparatorTextViewStyle

?android:selectableItemBackground

?android:textAppearanceListItemSmall

?android:textSelectHandleLeft

45

46

Dividers

Dividers and spacing (e.g. margins) establish hierarchy

47

Dividers

48

Borderless buttons

49

Button bars

Button bar style automatically adds dividers between buttons

Remember, preferred action on the right!

50

Button bars

51

Touch feedback ...

Or android:background on any view type android:listSelector for lists and grids

52

List headings 14sp, bold, ALL CAPS (same as action bar tabs and action bar item titles)

2dp separator



53

Sophisticated typography with TextView

android:fontFamily="sans-serif-thin"

android:fontFamily="sans-serif-light"

(default) android:fontFamily="sans-serif-condensed"

Download standard, condensed, and slab at

Google Fonts

54

Full-bleed images with consistent aspect ratios

1dp separator

centerCrop:

55

Generating Holo assets Android Asset Studio

ANDROID-UI-UTILS.GOOGLECODE.COM

Action Bar Style Generator

ACTIONBARSTYLEGENERATOR.COM

Android Holo Colors

ANDROID-HOLO-COLORS.COM

56

Generating Holo assets Android Asset Studio

ANDROID-UI-UTILS.GOOGLECODE.COM

Action Bar Style Generator

ACTIONBARSTYLEGENERATOR.COM

Android Holo Colors

ANDROID-HOLO-COLORS.COM

57

Generating Holo assets Android Asset Studio

ANDROID-UI-UTILS.GOOGLECODE.COM

Action Bar Style Generator

Jeff and Jérôme are ACTIONBARSTYLEGENERATOR.COM in the Developer Sandbox!

Android Holo Colors

ANDROID-HOLO-COLORS.COM

58

Thank You! +Roman Nurik +Nick Butcher

Developers