实现目标:提取随意一张图片的7种颜色(图片拥有7种以上的颜色),可作为背景色使用。
布局(自己增添toolbar):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rl"
tools:context=".BackgroundActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@mipmap/fp"
android:scaleType="centerCrop"
android:id="@+id/img"
android:layout_below="@+id/toolbar"
android:layout_alignParentStart="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"