Android Question How i can add border to text?

mangojack

Expert
Licensed User
Longtime User
Declare the Label as B4XView and set the Width to -2 (autosize depending on text)

B4X:
    Label1.Width = -2    'Can be done in Designer also ..
    Label1.Text = "12345"
    Label1.SetColorAndBorder(xui.Color_White, 2dip, xui.Color_Black, 0)
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
The above code results in the following ...



If this is not the desired result , possibly this thread might help.

 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Haven' go time to test it , but possibly download the correct / wanted font from a free font site and load it from assets using xui.CreateFont() maybe ?
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
there are Errors
You should post your error messages as text ...


Upload your project as a .zip file.

Non B4XPages project : File Menu > Export as Zip

B4XPages project :
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
other simple.
You can move the outline wherever you want, the trick is in the x,y position.
B4X:
DrawTextWithOutline("Hello, World!", 100, 100, xui.Color_White, xui.Color_Black, 48)
B4X:
Sub DrawTextWithOutline(text As String, x As Float, y As Float, textColor As Int, outlineColor As Int, textSize As Float)
    Dim xFont As B4XFont = xui.CreateDefaultFont(textSize)
    xCanvas.DrawText(text, x - 1, y, xFont, outlineColor, "LEFT")
    xCanvas.DrawText(text, x + 1, y, xFont, outlineColor, "LEFT")
    xCanvas.DrawText(text, x, y - 1, xFont, outlineColor, "LEFT")
    xCanvas.DrawText(text, x, y + 1, xFont, outlineColor, "LEFT")
    xCanvas.DrawText(text, x, y, xFont, textColor, "LEFT")
    xCanvas.Invalidate
End Sub
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
other Thickness and color

B4X:
DrawTextWithOutline("Hello, World!", 100, 100, 3, 0xB5FFFFFF, xui.Color_Yellow, 48)

B4X:
Sub DrawTextWithOutline(text As String, x As Float, y As Float, Thickness As Int, textColor As Int, outlineColor As Int, textSize As Float)
    Dim xFont As B4XFont = xui.CreateDefaultFont(textSize)
    xCanvas.DrawText(text, x - Thickness, y, xFont, outlineColor, "LEFT")
    xCanvas.DrawText(text, x + Thickness, y, xFont, outlineColor, "LEFT")
    xCanvas.DrawText(text, x, y - Thickness, xFont, outlineColor, "LEFT")
    xCanvas.DrawText(text, x, y + Thickness, xFont, outlineColor, "LEFT")
    xCanvas.DrawText(text, x, y, xFont, textColor, "LEFT")
    xCanvas.Invalidate
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…