有没有一种系统级的方法来调用这些颜色选择器,就像 Google 日历应用程序中那样?还是我需要自己构建它?
有没有一种系统级的方法来调用这些颜色选择器,就像 Google 日历应用程序中那样?还是我需要自己构建它?
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通道,只有这样才能保证颜色完美无误!