安卓取色盘自定义View依赖库
标签搜索

安卓取色盘自定义View依赖库

Pop.Kite
2023-01-28 / 2 评论 / 96 阅读 / 正在检测是否收录...

安卓取色盘View

Android custom View to achieve the color palette

引入依赖

  1. setting.gradle下添加仓库
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        //...
        maven { url 'https://jitpack.io' }
    }
}
  1. 应用的build.gradle下添加依赖
    implementation 'com.github.popkter:ColorPickView:v0.1'

使用方法

  1. 属性
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="color_picker">
        <!-- 背景圆的半径 -->
        <attr name="circle_radius" format="dimension" />
        <!-- 可滑动小球的半径 -->
        <attr name="center_radius" format="dimension" />
        <!-- 可滑动小球的颜色 -->
        <attr name="center_color" format="color" />
        <!-- 圆环还是原型取色盘 -->
        <attr name="is_ring" format="boolean" />
        <!-- 圆环的半径 -->
        <attr name="ring_radius" format="dimension" />
    </declare-styleable>
</resources>
  1. 引用
    <com.popkter.colorpickview.ColorPickerView
        android:id="@+id/color_picker_view"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_gravity="center"
        app:center_color="#ffffff"
        app:center_radius="13dp"
        app:circle_radius="100dp"
        app:is_ring="false"
        app:ring_radius="20dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginBottom="20dp"/>
  1. 监听
//监听颜色变化,返回一个hsb的值,可通过hsbToRgb(float[] hsb)方法转为rgb值
mColorPickerView.setOnColorChangedListener(hsb -> {});

使用效果

自定义取色盘view依赖效果图.mp4

2

评论 (2)

取消
  1. 头像
    LL
    iPhone · Google Chrome

    表情爱了爱了!

    回复
    1. 头像
      popkter 作者
      MacOS · Safari
      @ LL

      表情

      回复