需要添加jar包

  android-support-v7-cardview.jar
  android-support-v7-palette.jar

CardView

CardView继承自FrameLayout类,可以在一个卡片布局中一致性的显示内容,卡片可以包含圆角和阴影。

CardView的属性:

背景色

  XML: android:cardBackgroundColor 

  JAVA: setCardBackgroundColor(int) 

圆角半径

  XML: android:cardCornerRadius 

  JAVA: setRadius(float) 

阴影

  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

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

posted on 2015-06-23 14:24  道无涯  阅读(544)  评论(0编辑  收藏  举报