須要添加jar包android
android-support-v7-cardview.jar
android-support-v7-palette.jar
CardView繼承自FrameLayout類,能夠在一個卡片佈局中一致性的顯示內容,卡片能夠包含圓角和陰影。佈局
CardView的屬性:spa
背景色code
XML: android:cardBackgroundColor xml
JAVA: setCardBackgroundColor(int) blog
圓角半徑繼承
XML: android:cardCornerRadius get
JAVA: setRadius(float) it
陰影io
XML: android:cardElevation
JAVA: setMaxCardElevation(float)
佈局文件中建立CardView
<!-- A CardView that contains a TextView --> <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/card_view" android:layout_gravity="center" android:layout_width="200dp" android:layout_height="200dp" card_view:cardCornerRadius="4dp"> <TextView android:id="@+id/info_text" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.v7.widget.CardView>
使用 xmlns:card_view="http://schemas.android.com/apk/res-auto" 可用向下兼容,不然只能在5.0上有效
Palette從圖像中提取突出的顏色,這樣能夠把色值賦給ActionBar、或者其餘,可讓界面整個色調統一,效果見上圖(Palette)。
Palette這個類中提取如下突出的顏色:
Vibrant (有活力)
Vibrant dark(有活力 暗色)
Vibrant light(有活力 亮色)
Muted (柔和)
Muted dark(柔和 暗色)
Muted light(柔和 亮色)
提取色值代碼以下:
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.abc_ab_share_pack_mtrl_alpha); Palette palette = Palette.generate(bm); if (palette.getLightMutedSwatch() != null) { int color = palette.getLightVibrantSwatch().getRgb(); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color)); }
2015-06-23
14:25:05