import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.graphics.nativeCanvas
import androidx.compose.ui.unit.dp
@Composable
fun InlineColoredText(
text : String, setTextSize : Float = 64f ,
setStrokeWidth : Float = 12f,
setStrokeMiter : Float = 10f,
setTextColor : Int = android.graphics.Color.BLACK,
setBackgroundTextColor : Int = android.graphics.Color.WHITE){
val textPaintStroke = Paint().asFrameworkPaint().apply {
isAntiAlias = true
style = android.graphics.Paint.Style.STROKE
textSize = setTextSize //64f
color = setTextColor
strokeWidth = setStrokeWidth
strokeMiter = setStrokeMiter
strokeJoin = android.graphics.Paint.Join.ROUND
}
val textPaint = Paint().asFrameworkPaint().apply {
isAntiAlias = true
style = android.graphics.Paint.Style.FILL
textSize = setTextSize // 64f
color = setBackgroundTextColor
}
Canvas(
modifier = Modifier.fillMaxSize(),
onDraw = {
drawIntoCanvas {
it.nativeCanvas.drawText(
text,
0f,
120.dp.toPx(),
textPaintStroke
)
it.nativeCanvas.drawText(
text,
0f,
120.dp.toPx(),
textPaint
)
}
}
)
}
사용예제
'Android Dev > Compose' 카테고리의 다른 글
Compose Dialog resize 안되는 문제 (0) | 2022.06.23 |
---|---|
Compose Preview - viewmodel 연결 (0) | 2022.04.28 |
Dagger Hilt Testing Error - error: cannot find symbol @ScopeMetadata, @QualifierMetadata (0) | 2022.03.10 |
jcenter() deprecated에 따른 repository파일 부재(bad gate way) 문제 해결(ex : ucrop) (0) | 2022.03.04 |
Classes trial, variable initializing (0) | 2022.02.28 |