button color

fdx12345

Active Member
Licensed User
Longtime User
I am trying to set the color of a button via program on startup and am having difficulting even getting the button to show up (black screen only). Everything looks good in the emulator window when using the designer, but when I compile (with no errors), the resulting program on the emualtor is a blank (black) sceen with no buttons. Using the Designer, I should have a blue button on a white background.

Bill
 

margret

Well-Known Member
Licensed User
Longtime User
Something like this:

B4X:
Sub Globals
   Dim Btn1 As Button
   Btn1.Initialize("Btn1")
   Activity.AddView(Btn1, 10, 10, 150, 40)
   Btn1.Text = "Click Here"
   Btn1.Color = Colors.White
   Btn1.TextColor = Colors.Blue
End Sub
Sub Activity_Create(FirstTime As Boolean)
End Sub
Sub Btn1_Click
   Msgbox("It Clicked", "")
End Sub

If you are using a file created with the designer, you need to load the layout file:

B4X:
Activity.LoadLayout("yourfilename.bal")
 
Last edited:
Upvote 0

fdx12345

Active Member
Licensed User
Longtime User
Initializing Button Color

How do I cut/paste code into the reply window? I cannot get the resulting paste to fit and the code is not colored as in your example? I tried what you suggested but it did not work. I need to show my code.

Bill
 
Upvote 0

fdx12345

Active Member
Licensed User
Longtime User
Got it to work but]still need to know how to cut/paste code into this reply window with color.

Discovered I had to initialize the buttons first then load the layout file created with the designer, then set the button colors and it had to be done in that order. I could do all three steps in the Global or in Activity_Create secdtions. Went something like this:

Button1.Initialize("Button1")
Activity.LoadLayout("MainMenu") 'created in Designer
button1.color=Blue


If I changed the above order in any fashion, it did not work.

Bill
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
You shouldn't have to initialize it if you are loading the button in the layout file.
And to display code wrap the text in CODE brackets

Sent from my DROIDX
 
Upvote 0

fdx12345

Active Member
Licensed User
Longtime User
You were right! I took out the initialization (1st line) and it still worked. Thanks much.

Bill
 
Upvote 0

fdx12345

Active Member
Licensed User
Longtime User
code brackets

What are code brackets??
Are then {} ??????

Testing:

{ Dim Button_Setup As Button
Dim Status As Button
Dim Bills As Button
}
 
Upvote 0

fdx12345

Active Member
Licensed User
Longtime User
testing code brackets

maybe these are the backets: []

[ Dim Button_Setup As Button
Dim Status As Button
Dim Bills As Button
]
 
Upvote 0

Jost aus Soest

Active Member
Licensed User
Longtime User
How to show code in postings

How to show code:

If you post something, above the edit field you can find many formatting symbols like:
"B" for bold
"I" for italic
and so on. One of the last ones is the "#" for formatting your code.

So enter or copy&paste your code into your posting, select all the pasted code, and press "#".

Example:

1. Enter some code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim i As Int 'This is a comment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2. Select the whole code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim i As Int 'This is a comment <-- Selected text (normaly white on dark)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(Best with mouse)

3. Press "#":
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ CODE]Dim i As Int 'This is a comment[ /CODE]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The "brackets" are the CODE-Tags in "[" and "]".

4. After sending your posting:
B4X:
Dim i As Int 'This is a comment

5. Voila!
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…