Button Colors Not Consistent

Guardian17

Active Member
Licensed User
Longtime User
I'm trying to create my own QWERTY keyboard for use in a game, partly for the learning aspect of creating an array of buttons. This is a modified version of the Tick-Tack-Toe example on your site. Here's my code:

B4X:
Sub Process_Globals
   Dim ButtonsText(30) As String
End Sub

Sub Globals
   Dim Buttons(30) As Button
   Dim KeyLegends As String  :KeyLegends = "QWERTYUIOPASDFGHJKLZXCVBNM"
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Create QWERTY Keyboard
   Dim width, offsetX, offsetY As Int
   width = 35dip
   For i = 0 To 25
      If i<10 Then
         offsetX = (100%x - (10-i) * (width-8) - 20)
         offsetY = 100%y - width * 3 - 8
      Else If i<19 Then
         offsetX = (100%x - (20-i) * (width-8))
         offsetY = 100%y - width * 2 - 10
      Else
         offsetX = (100%x - (28-i) * (width-8) - 5)
         offsetY = 100%y - width - 12
      End If
      Dim b As Button
      b.Initialize("button") 'All buttons share the same event sub
      b.TextSize = 12
      'b.Color = Colors.RGB(0,0,255)
      'b.textColor = Colors.RGB(0,0,0)
      b.Tag = KeyLegends.SubString2(i,i+1)
      b.Text = b.Tag
      Activity.AddView(b,offsetX, offsetY, width, width)
      Buttons(i) = b 'store a reference to this view
   Next
End Sub

I'm currently displaying this keyboard at the bottom of a 480W x 800H sample screen. (I know there are other things to be done for the various possible screen sizes).

If run as shown, I get nice white buttons with black letters and adequate dark spacing between all buttons.

If I un-comment the "b.color" and "b.textColor" lines to experiment with making buttons a different color (each key will need to take on one of several colors for my game program throughout the game), and then run the program again, the buttons appear in the same positions, but the spaces between the buttons also take on the same blue button color (essentially the buttons are larger than the first case) so there is no separation visible between the buttons.

Why do the default colors work correctly, but my own choice of colors cause the problem mentioned?
 
Top