Android Question button with icon & text

sorex

Expert
Licensed User
Longtime User
Hello,

I have a question about a button view having an icon and text.

I added such view and added a bitmap drawable to the button enabled state
and forced the fill to the top left.

In the (deadslow) AVD emulator I can see the icon and text but the text label seems not big enough.

On my phone (i5800 at 240x400) I only see the icon?

The labelsize is this depending on the button height? I used the height of the icon which is 32x32px.
 

Attachments

  • phone.png
    phone.png
    8.6 KB · Views: 556
  • emu.gif
    emu.gif
    68.8 KB · Views: 698
  • settings.gif
    settings.gif
    20.8 KB · Views: 544

sorex

Expert
Licensed User
Longtime User
I'll add text in this post as I progress...

I tried aligning the text to the top but nothing changes.

When I set text align to left I saw odd pixels in the icon.
When forcing the color to white the text is there so for some reason I thought the default color is black on my phone?

So I added a label and normal button to the layout.

The label color is grey, but the button color is black!

I think you need to check for drawable bitmap enable if that's the case then use the label default color and not button black unless there is another color already selected.

so 1 problem is solved for now. the label height is still wrong tho.
 

Attachments

  • phone2.png
    phone2.png
    10.5 KB · Views: 497
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime User
I don't know if the button view is something Android OS specific or custom code but it seems that it is a labeling positioning problem.

The text line gets padded too much that's why some pixels are not visible.

It happends in both button styles as you can see in the attached screenshot.

Strange thing is that both are defined as 32px but the icon seems larger.

Any way to solve this without the need to create a seperated image, label for text and hotspot
 

Attachments

  • emu2.gif
    emu2.gif
    5.1 KB · Views: 358
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Do it just after you load the layout:

B4X:
Dim JO As JavaObject = Button1
JO.Runmethod("setPadding",Array As Object(0,0,0,0))

And experiment with the padding
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
You rule, Steve!

Dim JO As JavaObject = Button1 'left button
JO.Runmethod("setPadding",Array As Object(0,8,0,0))

Dim JO As JavaObject = Button3 'right button
JO.Runmethod("setPadding",Array As Object(0,-8,0,0))

give what you see in the attachment. not sure why it needs to be negative on the right one tho, but it works.

Thanks a lot!

By the way is er a way to have the button look + icon & text?
 

Attachments

  • emu3.gif
    emu3.gif
    5.2 KB · Views: 445
Upvote 0
Top