Android(Lollipop/5.0) Material Design(七) 保持相容性

來源:互聯網
上載者:User

標籤: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(七) 保持相容性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.