Giter Club home page Giter Club logo

colorpicker's Introduction

Android 自定义 View - 颜色选取器(水平、竖直)

Android 自定义 View - 颜色选取器(水平、竖直)

类似 SeekBar 的方式通过滑动粗略选择颜色。

效果图

xml 属性

  1. indicatorColor 指示点颜色
  2. indicatorEnable 是否使用指示点
  3. orientation 方向 horizontal 水平 vertical 竖直

使用

复制 \library\src...\ColorPickerView.java 和 \library\src\main\res\values\attrs.xml 文件到你的项目中,就可以在使用啦。

示例: 在 xml 中使用:

    <com.duan.colorpicker.ColorPickerView <!--替换包名-->
        android:layout_width="50dp"
        android:layout_height="200dp"
        app:indicatorEnable="true"
        app:indicatorColor="#fff"
        app:orientation="vertical" />

在 java 中使用:

...
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ColorPickerView picker = (ColorPickerView) findViewById(R.id.colorPickerView);
        picker.setIndicatorColor(Color.GREEN);
        picker.setOrientation(ColorPickerView.Orientation.HORIZONTAL);
        picker.setColors(Color.DKGRAY,Color.RED,Color.WHITE);
        picker.setOnColorPickerChangeListener(new ColorPickerView.OnColorPickerChangeListener() {
            @Override
            public void onColorChanged(ColorPickerView picker, int color) {
                // TODO
            }

            @Override
            public void onStartTrackingTouch(ColorPickerView picker) {
                // TODO

            }

            @Override
            public void onStopTrackingTouch(ColorPickerView picker) {
                // TODO

            }
        });
        }
...

实现分析可参看博文: Android 自定义 View - 颜色选取器(水平、竖直)

2017-08-16

1 修复 onLayout 重复执行时指示点位置重置和颜色条重置的错误
2 添加 getColor 方法以获取当前指示点所指的颜色
3 覆写 onRestoreInstanceState 和 onSaveInstanceState 方法,使能够在屏幕旋转时保存状态

colorpicker's People

Contributors

duanjianing avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.