Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private fun writeCloud(text: String): BitmapDrawable {
- // Draw bitmap
- val drawable = ContextCompat.getDrawable(context, R.drawable.ic_cloud)
- val bitmap = Bitmap.createBitmap(drawable?.intrinsicWidth ?: 68f.toPx.toInt(),
- drawable?.intrinsicHeight ?: 48f.toPx.toInt(), Bitmap.Config.ARGB_8888)
- val textPaint = TextPaint().apply {
- style = Paint.Style.FILL
- color = Color.BLACK
- flags = Paint.ANTI_ALIAS_FLAG
- xfermode = PorterDuffXfermode(PorterDuff.Mode.XOR)
- textSize = resources.getDimension(R.dimen.CloudSeekBar_thumbTextSize)
- typeface = Typeface.create(typeface, Typeface.BOLD)
- }
- val canvas = Canvas(bitmap)
- drawable?.setBounds(0, 0, canvas.width, canvas.height)
- drawable?.draw(canvas)
- // Draw text
- val bounds = canvas.clipBounds
- val textWidth = textPaint.measureText(text)
- canvas.drawText(text,
- bounds.centerX() - textWidth / 2f,
- (bitmap.height + resources.getDimensionPixelSize(R.dimen.CloudSeekBar_thumbHorizontalPadding)) / 2f,
- textPaint)
- return BitmapDrawable(resources, bitmap)
- }
Add Comment
Please, Sign In to add comment