aj
02/19/2024, 8:19 PMKaren Frangulyan
02/19/2024, 8:44 PMaj
02/19/2024, 8:45 PMaj
02/19/2024, 8:46 PMKaren Frangulyan
02/19/2024, 8:59 PM@Composable
fun StrokedText(
text: String,
modifier: Modifier = Modifier,
textColor: Color = Color.Black,
strokeColor: Color = Color.White,
strokeW: Float = 4f,
fontSize: Int = 16
) {
Canvas(modifier = modifier) *{*
val paint = _Paint_().asFrameworkPaint()._apply_ *{*
_isAntiAlias_ = true
_style_ = android.graphics.Paint.Style._FILL_AND_STROKE_
_textSize_ = fontSize._sp_._toPx_()
_color_ = textColor._toArgb_()
}
val strokePaint = _Paint_().asFrameworkPaint()._apply_ *{*
_isAntiAlias_ = true
_style_ = android.graphics.Paint.Style._STROKE_
_textSize_ = fontSize._sp_._toPx_()
_strokeWidth_ = strokeW
_color_ = strokeColor._toArgb_()
}
// Calculate text size to position it in the center
val textBounds = android.graphics.Rect()
paint.getTextBounds(text, 0, text.length, textBounds)
drawContext.canvas._nativeCanvas_.drawText(
text,
size.width / 2 - textBounds.exactCenterX(),
size.height / 2 - textBounds.exactCenterY(),
strokePaint
)
drawContext.canvas._nativeCanvas_.drawText(
text,
size.width / 2 - textBounds.exactCenterX(),
size.height / 2 - textBounds.exactCenterY(),
paint
)
}
}
@Preview
@Composable
fun CustomStrokedTextExample() {
StrokedText(
text = "Hello, World!",
modifier = Modifier
._fillMaxWidth_()
._height_(100._dp_),
textColor = Color.Black,
strokeColor = Color.Red,
strokeW = 4f,
fontSize = 24
)
}
At least the preview in Android Studio looks good to meKaren Frangulyan
02/19/2024, 9:00 PMStylianos Gakis
02/19/2024, 9:08 PMaj
02/19/2024, 9:10 PMKaren Frangulyan
02/19/2024, 9:22 PMKaren Frangulyan
02/19/2024, 9:27 PMMR3Y
02/20/2024, 12:13 AMColton Idle
02/20/2024, 5:22 PMMR3Y
02/20/2024, 5:42 PMKaren Frangulyan
02/20/2024, 7:56 PMaj
02/21/2024, 7:45 AMKaren Frangulyan
02/21/2024, 9:04 AM