Android Question typeface not initialized

Didier9

Well-Known Member
Licensed User
Longtime User
I am using a typeface within the DrawText method on a canvas.
I declare the typeface with "Dim tf As Typeface" and I use it in the DrawText call and it works, but I am getting a warning that Variable 'tf' was not initialized.
There is no "Initialize" method for a typeface. How can I get rid of the error message?
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Hi,

Why you declare tf?
Why you just don't use typeface like that example?

canvas1.DrawText("This is a nice sentence.", 200dip, 200dip, Typeface.DEFAULT_BOLD, 30, Colors.Blue, "LEFT")
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Because when I do not declare it, I get "Undeclared variable 'tf' is used before it was assigned any value." and that is an error, so the code does not compile.
By declaring it, I just get a warning and the code compiles and runs.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Because when I do not declare it, I get "Undeclared variable 'tf' is used before it was assigned any value." and that is an error, so the code does not compile.
By declaring it, I just get a warning and the code compiles and runs.

Sorry, too quick of a response. Your code does work, thank you.
I am not sure where I got the original code from, but this is simpler anyways.

For completeness, here is how I was using it:
B4X:
Dim tf as TyeFace
canvas1.DrawText("This is a nice sentence.", 200dip, 200dip, tf.CreateNew(Typeface.DEFAULT, Typeface.STYLE_NORMAL), 30, Colors.Blue, "LEFT")
Thanks!
 
Last edited:
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
That code is not mine. I just copied it. In B4A autocomplete / intellisense there is the link example: (copy). Correct code 115% of the time.

canvas1.DrawText...
 
Upvote 0
Top