Android Question Add an image to a button

rgarnett1955

Active Member
Licensed User
Longtime User
Hi

I have been trying to programmatically change the image on a button.

I have the image files in the files directory and can see them in the files pane.

The code i have been trying is:
Toggle the image on the button:
Sub tb5_Click
    Dim dimStyleStr As String
    Dim filename As String
    
    If pnlAlarms.Visible = True Then
        pnlAlarms.Visible = False
        lw.Visible = False
        washPane.Visible =False
        dimStyleStr = "-fx-background-image: url(" & Chr(34) & File.DirAssets & "AlarmPageShow.png" & Chr(34) & ")"
        tb5.Style = dimStyleStr
    Else
        pnlAlarms.Visible = True
        lw.Visible = True
        washPane.Visible = True
        
        dimStyleStr = "-fx-background-image: url(" & File.DirAssets & Chr(34) & "\AlarmPageHide.png" & Chr(34) & ")"
        tb5.Style = dimStyleStr
'        tb5.Font  = fx.CreateFontAwesome(16)
'        tb5.Text  = Chr(0xF039)
'        tb5.TextColor = fx.Colors.From32Bit(0xFF00FF1D)
    End If
    
End Sub

I just don't get how to set the tb5.Style string so that it gets the file and displays it. How can I do this?

How do you find out how to set up style strings?

Best regards
Rob
 

DonManfred

Expert
Licensed User
Longtime User
Is this a B4A Question?
 
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
Hello!

I didn't use the words copy and paste as far as I can see.

I already looked at the post you suggested and I'm sorry to be dumb, but I just don't get it. We can't all be geniuses at java which lies behind B4X. I don't know java, CSS's, HTML etc etc that's why I use B4X. I am not trying to split the atom I am just trying to change a pix on a button. Something I can do in VBA or c without a lot of pain.

I have spent hours googling and searching the B4X community site, but I just can't work it out. If the problem was about an embedded processor using straight C and not object oriented spaghetti, I would be able to cope.

Obtuse, cryptic answers may make the provider of them feel powerful and smarter than me and I accept that many people are smarter than me. There is no question about that. In fact if I thought I was the smartest person on earth I would hardly have asked for help as it would be rather pointless.

Can anybody else help me with this? A straightforward answer would be really nice.


Best regards

Rob
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Firstly .. as asked in post #2 , Is this related to B4J or B4A ? The posted code appears to be B4J, in which case the question would be better asked in the B4J forum.

Edit: If it is related to B4J ... this might be of interest
 
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
did someone say C?
 

Attachments

  • c.jpg
    c.jpg
    93.6 KB · Views: 173
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
Firstly .. as asked in post #2 , Is this related to B4J or B4A ? The posted code appears to be B4J, in which case the question would be better asked in the B4J forum.

Edit: If it is related to B4J ... this might be of interest

Hi MJ

I thought B4X was cross platform and in general the code should work in all environments. I had exactly the same problem with images in B4A.

What should I now do? Should copy the question into the "correct forum" or might it be reasonable to hope that someone may help.

Best regards

Rob
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The answers to one of these may help you:


Or


otherwise there are a few more : https://www.b4x.com/android/forum/pages/results/?query=B4j+Button+image
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Yes. I did.

Try using java or, B4? or C++ on an embedded system that doesn't have G Bytes if ram and that meets the MISRA rules for embedded software.

Some of us use software for purposes other than generating eye candy for mobile phones.

Best of luck with that.

Best regards

Rob

some pray the rosary to show their devotion; i too program in C to keep the synapses firing. by the way, you can develop in C on android: Android NDK. or you can get in the flow with b4x. your secret will be safe with us.
 
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
The answers to one of these may help you:


Or


otherwise there are a few more : https://www.b4x.com/android/forum/pages/results/?query=B4j+Button+image
Thanks very much for that Steve

I will have a look at these.

Best regards
Rob
 
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
some pray the rosary to show their devotion; i too program in C to keep the synapses firing. by the way, you can develop in C on android: Android NDK. or you can get in the flow with b4x. your secret will be safe with us.

The strange thing is they all use sqLite3 on androids, i phones etc. This is written in pure ANSI C. It's fast, robust, brilliant and FREE. You can bolt it on to anything and away you go!

I like high level languages and have done a lot of Matlab, a little Python and a heap of VBA. I like b4X as I can't stand Java; it seems a hard way of doing simple things. A language without unsigned integers? What genius thought that up?

Whoever it was had obviously been out in the Sun far too long.

I've heard about C for android, but I'm worried it's all C++ which like Java is really a meta-language that requires constant Googling of the libraries to work out how to do stuff.

Best regards

Rob
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Replace these lines:
dimStyleStr = "-fx-background-image: url(" & Chr(34) & File.DirAssets & "AlarmPageShow.png" & Chr(34) & ")"
by this:
dimStyleStr = "-fx-background-image: url('" & File.GetUri(File.DirAssets, "AlarmPageShow.png") & "')"

I hadn't done this before, I searched in the forum, found a solution, tested it and it works !
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Hello!

I didn't use the words copy and paste as far as I can see.

I already looked at the post you suggested and I'm sorry to be dumb, but I just don't get it. We can't all be geniuses at java which lies behind B4X. I don't know java, CSS's, HTML etc etc that's why I use B4X. I am not trying to split the atom I am just trying to change a pix on a button. Something I can do in VBA or c without a lot of pain.

I have spent hours googling and searching the B4X community site, but I just can't work it out. If the problem was about an embedded processor using straight C and not object oriented spaghetti, I would be able to cope.

Obtuse, cryptic answers may make the provider of them feel powerful and smarter than me and I accept that many people are smarter than me. There is no question about that. In fact if I thought I was the smartest person on earth I would hardly have asked for help as it would be rather pointless.

Can anybody else help me with this? A straightforward answer would be really nice.


Best regards

Rob
I am a long time B4A user but new to B4J. I am like you. Expert in VBA but in these other languages I am just trying to get a job done. With B4J I have found I just have to spend some time on CSS https://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#listview. Mostly I lok for terms that sound like what I need and then Google them to find code I can use or modify. Update: The link above goes to the middle of the CSS page but you can scroll to the top.
 
Upvote 0
Top