Share
Embed
Transcript
84 slides
-
A Practical Guide to Material Design Implementation Yash Prabhu @yashvprabhu
github.com/yprabhu yprabhu.com dramafever.com -
Glossary ★ Screen Size ★ Screen density (ldpi, mdpi, hdpi,
xhdpi, xxhdpi, xxxhdpi) ★ Orientation (landscape/portrait) ★ Resolution (physical pixel) ★ Density Independent Pixel (virtual pixel) px = dp * (dpi / 160) -
How do I apply a theme? <style name="BaseStyle" parent="Theme.AppCompat.Light.NoActionBar"> <item
name="colorPrimary">@color/color_primary</item> <item name="colorPrimaryDark">@color/color_primary_dark</item> <item name="colorAccent">@color/color_accent</item> <item name="android:windowBackground"> @color/window_background </item> </style> @yashvprabhu -
Custom Fonts Google Fonts fonts.google.com Chris Jenkins’ Calligraphy Library github.
com/chrisjenx/Calligrap hy -
Custom Fonts // Programmatically defining typefaces TextView tv=(TextView)findViewById(R.id.custom); Typeface face=Typeface.createFromAsset(getAssets(),
"fonts/Verdana.ttf"); tv. setTypeface(face); // Using Chris Jenkins’ Calligraphy library <TextView android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content" fontPath="fonts/Verdana.ttf"/> -
Imagery Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R. drawable.bulbasaur); if (myBitmap !=
null && !myBitmap.isRecycled()) { Palette.from(myBitmap).generate(paletteListener); } -
Imagery continued.. Palette - Extracting colors from an image Palette.PaletteAsyncListener
paletteListener = new Palette.PaletteAsyncListener(){ @Override public void onGenerated(Palette palette) { int defColor = 0x000000; int vibrant = palette.getVibrantColor(defColor); int vibrantLight = palette.getLightVibrantColor(defColor); int vibrantDark = palette.getDarkVibrantColor(defColor); int muted = palette.getMutedColor(defaultColor); int mutedLight = palette.getLightMutedColor(defaultColor); int mutedDark = palette.getDarkMutedColor(defaultColor); }} -
Imagery - Raster vs Vector design.google.com/icons Raster Specific number of
pixels Vector Uses math to draw shapes using points, lines and curves -
Imagery - Scalable Vector Graphic <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24.0"
android:viewportHeight="24.0"> <path android:fillColor="#FF000000" android:pathData="M12,3c-4.97,0 -9,4.03 -9,9s4.03,9 9,9c0.83,0 1.5,-0.67 1.5,-1.5 0,-0.39 -0.15,-0.74 -0.39,-1.01 -0.23,-0.26 -0.38,-0.61 -0.38,-0.99 0,-0.83 0.67,-1.5 1.5,-1.5L16,16c2.76,0 5,-2.24 5,-5 0,-4.42 -4.03,-8 -9,-8zM6.5,12c- 0.83,0 -1.5,-0.67 -1.5,-1.5S5.67,9 6.5,9 8,9.67 8,10.5 7.33,12 6.5,12zM9.5,8C8.67,8 8,7.33 8,6.5S8.67,5 9.5,5s1.5,0.67 1.5,1.5S10.33,8 9.5,8zM14.5,8c-0.83,0 -1.5,-0.67 -1.5,-1.5S13.67,5 14.5,5s1.5,0.67 1.5,1.5S15.33,8 14.5,8zM17.5,12c- 0.83,0 -1.5,-0.67 -1.5,-1.5S16.67,9 17.5,9s1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5z"/> </vector> -
Ripples & Elevation Ripples (indicates touch input) ?android:attr/selectableItemBackground ?android:attr/selectableItemBackgroundBorderless android:colorControlHighlight
Elevation (lifts to your touch) • Resting 2dp • Raised 8dp @yashvprabhu -
app/build.gradle compile "com.android.support:palette-v7:24.1.1" compile "com.android.support:design:24.1.1" compile "com.android.support:appcompat-v7:24.1.1" compile "com.android.support:recyclerview-v7:24.1.1" compile
"com.android.support:cardview-v7:24.1.1" https://source.android.com/source/build-numbers.html -
Post-21 (Lollipop) <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/bg_button_yellow_pressed"/>
<item android:drawable="@drawable/bg_button_yellow_normal"/> </selector> -
Pre-21 (Lollipop) workaround <?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:colorControlHighlight"> <item
android:drawable="@drawable/bg_button_yellow_normal" /> </ripple> -
Floating Action Button Default Elevation: 6 dp Normal size: 56
dp Mini size: 40 dp -
FAB widget <android.support.design.widget.FloatingActionButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/ic_discuss" android:layout_margin="@dimen/fab_margin" android:clickable="true" app:fabSize="normal" app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end" /> -
Cards - compile 'com.android.support:cardview-v7:24.1.1' Card resting elevation: 2dp Card raised
elevation: 8dp @yashvprabhu -
CardView <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/card_margin"> <LinearLayout style="@style/Widget.CardContent" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:selectableItemBackground">
<!-- API Level 11 --> ….. </LinearLayout> </android.support.v7.widget.CardView> -
View Item <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center"> <ImageView android:id="@+id/avatar" android:layout_width="wrap_content"
android:layout_height="wrap_content" tools:src="@drawable/bulbasaur"/> <TextView android:id="@+id/text" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" tools:textColor="@color/black" tools:text="Bulbasaur" tools:textAppearance="?attr/textAppearanceListItem"/> -
Set LayoutManager & Adapter // Set either of these layout
managers recyclerView.setLayoutManager(new LinearLayoutManager(context)); recyclerView.setLayoutManager(new GridLayoutManager(context, GRID_SPAN)); recyclerView.setLayoutManager(new StaggeredGridLayoutManager (STAGGERED_GRID_SPAN, StaggeredGridLayoutManager.VERTICAL)); // Set adapter on recycler view recyclerView.setAdapter(new GridRecyclerViewAdapter(activity); -
Common Pattern CoordinatorLayout -- AppBarLayout -- Toolbar -- TabLayout --
ViewPager -- FloatingActionButton @yashvprabhu -
Common Pattern CoordinatorLayout -- AppBarLayout -- CollapsingToolbarLayout -- ImageView --
Toolbar -- NestedScrollView -- LinearLayout -- CardView -- Button -- FloatingActionButton @yashvprabhu -
Resources Udacity - Material Design for Android Developers Android Developer
Docs - Material Design Google Material Design Guidelines Material Doc Codepath Google IO 2016 Codelabs Plaid app by Nick Butcher MaterialWorld (Cheesesquare) -
Image Credit Windows Phone - Flat design iOS Phone -
Skeuomorphic design Android - Material Design PokemonDB Android Design Docs Android Developer docs