Activity.Title

parijs

Active Member
Licensed User
Longtime User
2 questions

How to change the background color off Activity.Title
and
How to center the Activity.Title

:signOops:
 

COBRASoft

Active Member
Licensed User
Longtime User
To center you could use an old trick... Place spaces in front of your title, it will require some trial and error, but should be doable.

Tip: Calculate how much dips (pixels) a space requires. Calulate the width of your text. Use Activity.Width to calculate how many spaces you will need...

Possible workaround: Make your activity fullscreen and draw your own title and background .
 
Last edited:
Upvote 0

COBRASoft

Active Member
Licensed User
Longtime User
That's why I gave the tip . You should 'calculate' the width of a space, preferable in dip. This way you can add spaces to the needs of your activity.width.

Is the given workaround no option for you?
 
Upvote 0

parijs

Active Member
Licensed User
Longtime User
I saw the centering text on a app form market and it looks nice
But I have one ListView with 27 different Activity.Titles. and then another 30 elsewhere
So I just leave it as it is.

Thanks.
 
Upvote 0

COBRASoft

Active Member
Licensed User
Longtime User
It's not perfect, but it works on my Xperia . Probably somebody can help you out with the correct typeface size of the title, I just guessed here.

Dim TitleWidth As Float
Dim strSpace As String
strSpace = " "
Dim SpaceWidth As Float

Dim objCanvas As Canvas
objCanvas.Initialize(Activity)
TitleWidth = objCanvas.MeasureStringWidth(Activity.Title, Typeface.DEFAULT, 12)
SpaceWidth = objCanvas.MeasureStringWidth(strSpace, Typeface.DEFAULT, 12)

Dim intWidth As Int
intWidth = Activity.Width

Dim intNeededSpaces As Int
intNeededSpaces = (intWidth / 2 - TitleWidth / 2) / SpaceWidth

For i = 0 To intNeededSpaces
Activity.Title = strSpace & Activity.Title
Next
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…