Cómo añadir una banda negra como Snapchat

lukas6410 -  
BunoCS Mensajes publicados 436 Fecha de registro   Estado Moderador Última intervención   -
Hola, busco colocar una banda negra detrás del texto. Aquí está la función que dibuja el texto
 public void drawMultilineTextToBimap(Context context,String text,Bitmap bitmap){ Resources resources = context.getResources(); float scale = resources.getDisplayMetrics().density; Bitmap.Config bitmapConfig = bitmap.getConfig(); if (bitmapConfig == null){ bitmapConfig = Bitmap.Config.ARGB_8888; } Canvas canvas = new Canvas(bitmap); //draw rect text Paint paintRect = new Paint(); paintRect.setColor(Color.BLACK); int heightrect = 100; int toprect = (bitmap.getHeight() - heightrect); int bottomRect = (bitmap.getHeight() + heightrect); canvas.drawRect(30, 30, 80, 80, paintRect); TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.WHITE); paint.setTextSize((int) (100 * scale)); paint.setShadowLayer(1f, 0f, 1f, Color.BLACK); int textWidth = canvas.getWidth() - (int) (16 * scale); // init StaticLayout for text StaticLayout textLayout = new StaticLayout( text, paint, textWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false); // get height of multiline text int textHeight = textLayout.getHeight(); // get position of text's top left corner float x = (bitmap.getWidth() - textWidth)/2; float y = (bitmap.getHeight() - textHeight)/2; // draw text to the Canvas center canvas.save(); canvas.translate(x, y); textLayout.draw(canvas); canvas.restore(); } 


Configuration: Windows / Firefox 98.0

1 respuesta

  1. BunoCS Mensajes publicados 436 Fecha de registro   Estado Moderador Última intervención   3 930
     
    Hola,

    No está muy claro tu pedido.. ¿Puedes precisar lo que buscas hacer, con una captura de pantalla por ejemplo, y lo que ya logras hacer?

    --
    @+ 
    Buno, Moderador 
    La urgencia ya está resuelta, lo imposible está en marcha. Para los milagros, prevé un demora... 
    The urgent is done, the impossible is underway. For miracles, provide for a delay...
    0