Google日历颜色选择器

时间:2014-07-01 13:31:30

标签: android colors color-picker

是否有基于系统的方法来调用其中一个颜色选择器,就像在Google日历应用中一样?或者我是否可以自己构建它?

enter image description here

1 个答案:

答案 0 :(得分:5)

您需要使用Color Picker Collection

实现:

ColorPickerDialog colorcalendar = ColorPickerDialog.newInstance(
              R.string.color_picker_default_title, 
              mColor,
              mSelectedColorCal0,
              5,
              Utils.isTablet(this)? ColorPickerDialog.SIZE_LARGE : ColorPickerDialog.SIZE_SMALL);

  //Implement listener to get selected color value
  colorcalendar.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener(){

                @Override
                public void onColorSelected(int color) 
                {
                   // ADD MARKER
                   Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_mobileedge_navpoint);
                   bmp = changeBitmapColor(bmp, color);

                   googleMap.addMarker(new MarkerOptions()
                    .position(latLng)
                    .title("My Spot")
                    .snippet("This is my spot!")
                    .icon(BitmapDescriptorFactory.fromBitmap(bmp)));
                }

    });

  colorcalendar.show(getFragmentManager(),"cal");

更改位图颜色的功能:

 private Bitmap changeBitmapColor(Bitmap sourceBitmap, int color) {

        Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0,
                sourceBitmap.getWidth() - 1, sourceBitmap.getHeight() - 1);
        Paint p = new Paint();
        ColorFilter filter = new LightingColorFilter(color, 1);
        p.setColorFilter(filter);

        Canvas canvas = new Canvas(resultBitmap);
        canvas.drawBitmap(resultBitmap, 0, 0, p);

        return resultBitmap;
    }

我测试过,它工作正常!标记必须全部是白色的alpha,只有这样颜色才会完美!