Android(Lollipop/5.0)Material Design(8)互換性を保つ


Material Designシリーズ
Android(Lollipop/5.0)Material Design(一)概要
Android(Lollipop/5.0)Material Design(二)入門ガイド
Android(Lollipop/5.0)Material Design(3)Materialトピックを使用
Android(Lollipop/5.0)Material Design(4)リストとカードの作成
Android(Lollipop/5.0)Material Design(5)シャドウの定義とビューの切り取り
Android(Lollipop/5.0)Material Design(六)使用画像
Android(Lollipop/5.0)Material Design(7)カスタムアニメーション
Android(Lollipop/5.0)Material Design(8)互換性を保つ
公式サイト:https://developer.android.com/training/material/compatibility.html
代替スタイルの定義
あなたのappは、Material Designのトピックを使用してサポートされているデバイス上で実行され、以前のバージョンのデバイス上で以前のトピックを実行できます.
1.res/values/styles.xmlは、トピックの継承が早いトピックを定義します.
2.res/values-v 21/styles.xmlは、Materialトピックから継承された同じ名前のトピックを定義します.
3.manifestに定義されたトピックを適用する
注意:appが以前のトピックではなくMaterialトピックを使用している場合は、以前のバージョンのデバイスで実行できません.
Provide Alternative Layoutsは、layoutが5.0のxmlプロパティを参照しない場合、以前のバージョンのAndroidデバイス上で実行できる代替レイアウトを提供します.そうでなければ、代替レイアウトを提供できます.
代替レイアウトはres/layout-v 21/
コードの重複を避けるために、res/values/stylesを定義し、res/values-21/で新しいスタイルを定義し、styleの継承を使用して、res/valuesでbaseStyleを定義し、res/values-21で継承します.
Use the Support Libraryサポートライブラリv 7 support libraryを使用するには、次の機能があります.
・一つ適用したAppCompatのテーマの後で、システムのいくつかのコンポーネントはMaterial Designの風格があります
-ここだAppCompatトピックには、カラートピックがあります
・RecyclerViewコンポーネント表示データセット
・カードビューコンポーネント作成カード
・画像から色を取る
System widgetsシステムコンポーネントAppCompatトピックで提供されるMaterial Designスタイルのコンポーネントは、次のとおりです.
· EditText
· Spinner
· CheckBox
· Radiobutton
· SwitchCompat
· CheckedTextView
Color Paletteはv 7サポートライブラリを使用して、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はv 7サポートライブラリを使用すると、初期のAndroidバージョンでも実行できます.
Dependencies gradle依存:
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 higher
if (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:targetSdkValerson=21が必要です.