天天看點

Android 5.0+ 解析(三)Palette類

1.Palette簡單介紹

Palette中文翻譯:調色闆,android系統允許我們動态的擷取圖檔或者控件的顔色,來為布局控件提供顔色,保持統一的外觀顔色值。

使用Palette需要到sdk\extras\android\support\v7\palette目錄下-->打開libs目錄-->android-support-v7-palette.jar包-->copy到你項目的libs目錄下-->使用Palette。

2.Palette簡單使用

<span style="font-size:18px;">Palette.generateAsync(bmp, new Palette.PaletteAsyncListener() {
	@Override
	public void onGenerated(Palette palette) {
		Palette.Swatch swatch = palette.getVibrantSwatch();
		if(null != swatch) {
		mTextView.setBackgroundColor(swatch.getRgb());
		mTextView.setTextColor(swatch.getTitleTextColor());
		}
	}
});</span>
           

由于在Android裝置中,對圖像的處理有可能是耗時操作,是以,Palette類通過異步接口onGenerated回調的方法 

Android 5.0+ 解析(三)Palette類

通過調色闆更改了TextViewde字型顔色和背景色

來獲得Bitmap的顔色值。Palette類獲得的顔色值有以下幾種類型:  

<span style="font-size:18px;">Palette.Swatch a = palette.getVibrantSwatch();//有活力 
Palette.Swatch b = palette.getDarkVibrantSwatch();//有活力 暗色
Palette.Swatch c = palette.getLightVibrantSwatch();//有活力 亮色 
Palette.Swatch d = palette.getMutedSwatch();//柔和 
Palette.Swatch e = palette.getDarkMutedSwatch();//柔和 暗色
Palette.Swatch f = palette.getLightMutedSwatch();//柔和 亮色 我們從以上顔色中可以擷取到如下顔色值: 
int color1 = a.getBodyTextColor();//内容顔色 
int color2 = a.getTitleTextColor();//标題顔色
int color3 = a.getRgb();//rgb顔色 </span>
           

歡迎留言和評論!

部落格位址: http://blog.csdn.net/caihongdao123 

下一篇  Android 5.0+ 解析(四)Toolbar控件

繼續閱讀