Material Design Android

40
MATERIAL DESIGN ANDROID (FOR DEVELOPERS) BY MOHA MMAD SAM IULL A H FAR OOQUI

description

These slides contain basic overview of Material Design(new User Interface of Android) form a developers perspective.

Transcript of Material Design Android

Page 1: Material Design Android

MATERIA

L DESIG

N

ANDROID

(FOR D

EVELOPE

RS)

BY

MO

HA

MM

AD

SA

MI U

L L AH

FA

RO

OQ

UI

Page 2: Material Design Android

AGENDA

• Material theme

• Styles

• Layouts

• Elevation

• Widgets

• Animations

Page 3: Material Design Android

MATERIAL THEME

The new material theme provides:

• System widgets that let you set their color palette

• Touch feedback animations for the system widgets

• Activity transition animations

Page 4: Material Design Android

The material theme is defined as:

• @android:style/Theme.Material (dark version)

• @android:style/Theme.Material.Light (light version)

• @android:style/Theme.Material.Light.DarkActionBar

Page 5: Material Design Android

STYLE

<resources>  <!-- inherit from the material theme -->  <style name="AppTheme" parent="android:Theme.Material">    <!-- Main theme colors -->    <!--   your app's branding color (for the app bar) -->    <item name="android:colorPrimary">@color/primary</item>    <!--   darker variant of colorPrimary (for status bar, contextual app bars) -->    <item name="android:colorPrimaryDark">@color/primary_dark</item>    <!--   theme UI controls like checkboxes and text fields -->    <item name="android:colorAccent">@color/accent</item>  </style>

</resources>

Page 6: Material Design Android
Page 7: Material Design Android

LAYOUTS

 Layouts should conform to the material design guidelines

• Baseline grids

• Keylines

• Spacing

• Touch target size

• Layout structure

Page 8: Material Design Android

ELEVATIONS

Views can cast shadows, and the elevation value of a view determines the size of its shadow and its drawing order.

<TextView    android:id="@+id/my_textview"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="@string/next"    android:background="@color/white"    android:elevation="5dp" />

Page 9: Material Design Android
Page 10: Material Design Android

THE Z VALUE

Z = elevation + translationZ

To set the elevation of a view:

In a layout definition, use the android:elevation attribute.

In the code of an activity, use the View.setElevation method.

To set the translation of a view, use the View.setTranslationZ method.

The new ViewPropertyAnimator.z and ViewPropertyAnimator.translationZ 

methods enable you to easily animate the elevation of views.

Page 11: Material Design Android

SHADOWS AND OUTLINES

The bounds of a view's background drawable determine the default shape

of its shadow

Outlines represent the outer shape of a graphics object and define the

ripple area for touch feedback.

Page 12: Material Design Android

<TextView    android:id="@+id/myview"    ...    android:elevation="2dp"    android:background="@drawable/myrect" />

<!-- res/drawable/myrect.xml --><shape xmlns:android="http://schemas.android.com/apk/res/android"       android:shape="rectangle">    <solid android:color="#42000000" />    <corners android:radius="5dp" /></shape>

Page 13: Material Design Android

You can also create outlines in your code using the methods in

the Outline class, and you can assign them to views with

the View.setOutline method.

To prevent a view from casting a shadow, set its outline to null.

Page 14: Material Design Android

CLIPPING VIEWS

Clip a view to its outline area using the View.setClipToOutline method. Only

rectangle, circle, and round rectangle outlines support clipping, as

determined by the Outline.canClip method.

To clip a view to the shape of a drawable, set the drawable as the

background of the view (as shown above) and call

the View.setClipToOutline method.

Because clipping views is an expensive operation, don't animate the shape

you use to clip a view. To achieve this effect, use a Reveal Effect animation.

Page 15: Material Design Android

UI WIDGETS

Two new widgets

• RecyclerView

• CardView

Available in Android support library

Page 16: Material Design Android

RECYCLERVIEW

• Advanced version of ListView

• Item Views are recycled and can be scrolled efficiently

• Should be used with dynamically changing datasets

RecyclerView is easy to use, because it provides:

1. A layout manager for positioning items

2. Default animations for common item operations

Page 17: Material Design Android
Page 18: Material Design Android
Page 19: Material Design Android
Page 20: Material Design Android
Page 21: Material Design Android

CARDVIEW

CardView extends the FrameLayout class and lets you show information inside cards

that have a consistent look on any app. CardView widgets can have shadows and

rounded corners.

Here's how to specify properties of CardView:

• To set the corner radius in your layouts, the card_view:cardCornerRadius attribute.

• To set the corner radius in your code, use the CardView.setRadius method.

• To set the background color of a card, use the card_view:cardBackgroundColor attribute.

Page 22: Material Design Android
Page 23: Material Design Android

ANIMATIONS

• Touch feedback

• Reveal effect

• Activity transitions

• Curved motion

• View state changes

Page 24: Material Design Android

TOUCH FEEDBACK

The default touch feedback animations for buttons use the

new RippleDrawable class, which transitions between different states with a ripple

effect.

android:attr/selectableItemBackground 

android:attr/selectableItemBackgroundBorderless

RippleDrawable and set it as the background of your view

RippleDrawable as an XML resource using the ripple element

android:colorControlHighlight(style of material theme)

Page 25: Material Design Android

REVEAL EFFECT

ViewAnimationUtils.createCircularReveal

Page 26: Material Design Android

To reveal a previously invisible view using this effect:

Page 27: Material Design Android

To hide a previously visible view using this effect:

Page 28: Material Design Android

ACTIVITY TRANSITIONS

• enter transition

• exit transition

• shared elements transition

The Android L Developer Preview supports these enter and exit transitions:

• explode - Moves views in or out from the center of the scene.

• slide - Moves views in or out from one of the edges of the scene.

• fade - Moves views in or out of the scene.

Page 29: Material Design Android

The Android L Developer Preview also supports these shared elements transitions:

• changeBounds - Animates the changes in layout bounds of target views.

• changeClipBounds - Animates the changes in clip bounds of target views.

• changeTransform - Animates the changes in scale and rotation of target views.

• moveImage - Animates changes in size and scale type for an image view.

Page 30: Material Design Android
Page 31: Material Design Android

SPECIFY CUSTOM TRANSITIONS

Page 32: Material Design Android

The move_image transition in this example is defined as follows:

Page 33: Material Design Android

To enable window content transitions in your code instead, call the Window.requestFeature method:

Page 34: Material Design Android

To specify transitions in your code, call these methods with a Transition object:

• Window.setEnterTransition

• Window.setExitTransition

• Window.setSharedElementEnterTransition

• Window.setSharedElementExitTransition

The transition is activated when you launch another activity with the startActivity method.

Page 35: Material Design Android

SHARED ELEMENTS TRANSITIONS

To make a screen transition animation between two activities that have a shared element:

• Enable window content transitions in your style.

• Specify a shared elements transition in your style.

• Define your transition as an XML resource.

• Assign a common name to the shared elements in both layouts with the android:viewName attribute.

• Use the ActivityOptions.makeSceneTransitionAnimation method.

Page 36: Material Design Android
Page 37: Material Design Android

ANIMATING VIEW STATE CHANGES

The new StateListAnimator class lets you define animators that run when the state of

a view changes. The following example shows how to define an StateListAnimator as

an XML resource

Page 38: Material Design Android

The new StateListAnimator class lets you define animators that run when the state of a view changes. The following example shows how to define an StateListAnimator as an XML resource:

Page 39: Material Design Android

EXTRACTING PROMINENT COLORS FROM AN IMAGE

The Android L Developer Preview Support Library includes the Palette class

This class extracts the following prominent colors:

• Vibrant

• Vibrant dark

• Vibrant light

• Muted

• Muted dark

• Muted light

Palette.generate

Palette.generateAsync

Palette.getVibrantColor