J'ai besoin de faire de la couleur d'arrière-plan du texte dans EditText comme dans l'image.Comment créer des coins arrondis en arrière-plan de texte multiligne, où les lignes ont une largeur différente
Faire des coins arrondis et des rembourrages est assez facile avec LineBackgroundSpan
personnalisé. Je mis en œuvre comme ceci:
class RoundedCornersBackgroundSpan(val padding: Int,
val backgroundColor: Int) : LineBackgroundSpan {
val backgroundRect = Rect()
override fun drawBackground(c: Canvas, p: Paint, left: Int, right: Int, top: Int, baseline: Int, bottom: Int, text: CharSequence?, start: Int, end: Int, lnum: Int) {
if(text == null) return
val textWidth = Math.round(p.measureText(text, start, end))
val paintColor = p.color
backgroundRect.set(left - padding,
top - if(lnum == 0) { padding/2 } else { - (padding/2) },
left + textWidth + padding,
bottom + (padding/2))
p.color = backgroundColor
c.drawRoundRect(RectF(backgroundRect), 3.fromDpToPixelsF(), 3.fromDpToPixelsF(), p)
p.color = paintColor
}}
Mais comment puis-je mettre en œuvre ces coins « intérieurs », Wich annoté avec des flèches dans l'image?
Malheureusement, je ne trouve pas une meilleure solution. Il semble que le réglage manuel de l'arrière-plan est seulement possible. Mais j'essaie de rester dans les niveaux personnalisés "niveau" car gérer de nombreux editTexts semble beaucoup plus compliqué. Je poste ma solution bientôt, c'est presque terminé, mais c'est assez moche, gonflé et je n'aime pas ça. –