標籤:android material design
Define Alternative Styles 定義替代樣式讓你的app,使用Material Design的主題運行在支援它的裝置上,並在早期版本的裝置上可以運行較早的主題:1. 在res/values/styles.xml 定義一個主題繼承較早的主題2. 在res/values-v21/styles.xml 定義一個相同名字的繼承自Material主題 的主題 3. 在manifest中應用定義的主題註:如果你的app使用了Material 主題,而不提供較早的主題,那麼將不能運行在早期版本的裝置上
Provide Alternative Layouts 提供替代布局如果你設計的layout不引用任何的5.0中的xml屬性,那麼可以運行在早期版本的Android裝置上。否則,你可提供一個替代布局。替代布局建立在res/layout-v21/為了避免重複代碼,可以在res/values/ 定義你的styles,新風格的在res/values-21/ 中定義,並使用style的繼承,在res/values中定義一個baseStyle,在res/values-21中繼承它。
Use the Support Library 使用支援庫v7 support library 包括以下的一些特性:· 在應用了一個Theme.AppCompat 主題後,系統的一些組件就有了Material Design 的風格· 在Theme.AppCompat 主題中,有調色主題· RecyclerView 組件顯示資料集· CardView 組件建立卡片· 從映像中取色
System widgets 系統組件Theme.AppCompat 主題提供的Material Design 風格的組件有:
· EditText· Spinner· CheckBox· Radiobutton· SwitchCompat· CheckedTextView
Color Palette使用v7支援庫,獲得Material Design 風格定義顏色板,應用一個Theme.AppCompat 主題:
<!-- extend one of the Theme.AppCompat themes --><style name="Theme.MyTheme" parent="Theme.AppCompat.Light"> <!-- customize the color palette --> <item name="colorPrimary">@color/material_blue_500</item> <item name="colorPrimaryDark">@color/material_blue_700</item> <item name="colorAccent">@color/material_green_A200</item></style>
Lists and Cards使用v7支援庫後,在早期的Android版本上也可運行。
Dependenciesgradle 依賴:
dependencies { compile ‘com.android.support:appcompat-v7:21.0.+‘ compile ‘com.android.support:cardview-v7:21.0.+‘ compile ‘com.android.support:recyclerview-v7:21.0.+‘}Check the System Version 檢查系統版本
以下特性只能在Android 5.0(API層級21)及以上:
· Activity transitions 活動轉換
· Touch feedback 觸覺反饋
· Reveal animations 顯示動畫
· Path-based animations 基於路徑動畫
· Vector drawables 向量圖片
· Drawable tinting 圖片染色
檢查代碼:
// Check if we‘re running on Android 5.0 or higherif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Call some material design APIs here} else { // Implement this feature without material design}註:要讓app支援5.0,需要在manifest中Android:targetSdkVersion=21。
Android(Lollipop/5.0) Material Design(七) 保持相容性