Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

382
Views
¿Cómo convertir TextStyle de Jetpack Compose a android.graphics.Typeface?

Necesito dibujar texto en Canvas en Compose, para este propósito necesito un TextPaint con android.graphics.Typeface .

¿Hay alguna forma de convertir fácilmente Compose TextStyle en android.graphics.Typeface ?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Actualmente, la única solución que encontré es proporcionar recursos:

 val textTypeface: android.graphics.Typeface? = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) LocalContext.current.resources.getFont(R.font.quicksand_light) else null

Sin embargo, si la versión de Android <Android Oreo, no sé cómo proporcionar la fuente, así que recurro a la fuente predeterminada.

over 4 years ago · Santiago Trujillo Report

0

Para dibujar texto en el lienzo, puedes hacer esto

 @Composable fun DrawText() { val paint = Paint().asFrameworkPaint() Canvas(modifier = Modifier.fillMaxSize()) { paint.apply { isAntiAlias = true textSize = 24f typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD) // your typeface //other methods like color, dither, fontMetrics, shadow etc...are also available } drawIntoCanvas { it.nativeCanvas.drawText("Hello World", size.width/2, size.height/2, paint) } } }

Creo que convertir TextStyle (biblioteca de redacción) a tipo de typeface será una molestia ya que no hay soporte de Android. Si desea dibujar texto en lienzo, creo que esto será suficiente

over 4 years ago · Santiago Trujillo Report

0

prueba esto

 val textPaint = TextPaint() val context = LocalContext.current Canvas(modifier = Modifier.fillMaxWidth()) { textPaint.apply { typeface = Typeface.createFromAsset(context.assets, "fonts/yourfont.ttf") ... } drawContext.canvas.nativeCanvas.drawText("test", yourStart, yourEnd, X, Y, textPaint) }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!