Button design

PeterPetSil

Member
Licensed User
Longtime User
Hi!

I searched almost everything on this forum, but didn't find answer to my question.

I want to create a button, with solid color of blue and a white image of my design on top of that. When the button is pressed, the blue should turn into orange, but the white part should remain white.

I know, I can create two images for this and apply them to button on each event, but the problem with this method is, that when the button size is changed (device orientation, different devices,...), the image is scaled and not in proportions as it should be anymore. The symbol should allways be in same proportions.

Can someone give me a hint?

Thanks!

The example of button that I want is:

android_music_windows16.png
 

PeterPetSil

Member
Licensed User
Longtime User
Thnx, Erel!
I saw this tutorial, but didn't read it carefully enough. Now I paid a litle more attention and I'll try it out. :)
 
Upvote 0

PeterPetSil

Member
Licensed User
Longtime User
I have a problem here:

I loaded two 9Patch images into /Objects/res/drawable/ - Button1.png and Button1pressed.png
I imported the images into Designer and marked them as read-only in /Objects/res/drawable/ (not in /Files).

Then I edntered the code in main:

B4X:
Sub Activity_Create(FirstTime As Boolean)
 Activity.LoadLayout("1")
   
   Button.Top = 20%y
   Button.Left=15%x
   Button.Height = 5%y
   Button.Width=10%x
   
    SetNinePatchButton(Button,"button1.png","button1pressed.png")
   
End Sub

When I Run the project, I receive:

Packaging files. Error
res\drawable\Button1.png: Invalid file name: must contain only [a-z0-9_.]
res\drawable\Button1pressed.png: Invalid file name: must contain only [a-z0-9_.]
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
I have a problem here:

I loaded two 9Patch images into /Objects/res/drawable/ - Button1.png and Button1pressed.png
I imported the images into Designer and marked them as read-only in /Objects/res/drawable/ (not in /Files).

[...]

Packaging files. Error
res\drawable\Button1.png: Invalid file name: must contain only [a-z0-9_.]
res\drawable\Button1pressed.png: Invalid file name: must contain only [a-z0-9_.]

Use lowercase names for the files
 
Upvote 0

PeterPetSil

Member
Licensed User
Longtime User
Thanx, the lowercase worked, but now, I got an error at the device:

An error has occurred in sub: main_setninepatchbutton (java line:271)
java.lang
NoSuchFieldException: button1.png

The same thing happens if I use SetNinePatchButton2() function.
 
Last edited:
Upvote 0

PeterPetSil

Member
Licensed User
Longtime User
I removed png extension from code and it doesn't work.
I also removed png extension from files and it doesn't work either.

I also added Button1 in Designer (activity main) and in code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("main")
   
   
   Button1.Initialize("main")
   Activity.AddView(Button1,0,0,40,50)
   SetNinePatchButton2(Button1,"button1","button1pressed","","","")
End Sub

But this doesn't help.... :sign0013:
 
Upvote 0

PeterPetSil

Member
Licensed User
Longtime User
This is so wierd... I created another project, from scratch at another PC.

I receive the same error:
device-2012-04-23-132919.png


I removed the png extension from the code, but it is the same.

Attached is the new project.
 

Attachments

  • 9Patch.zip
    7.6 KB · Views: 299
Upvote 0

bluejay

Active Member
Licensed User
Longtime User
According to the tutorial Erel referred to in post #2 the image files should have names ending in '.9.png'.

BlueJay
 
Upvote 0

PeterPetSil

Member
Licensed User
Longtime User
According to the tutorial Erel referred to in post #2 the image files should have names ending in '.9.png'.

BlueJay

Thanks for the hint. I renamed files tu .9.png in /res/drawable folder and then I tested it with different variations in code:

B4X:
SetNinePatchButton(Button1,"button.9.png","buttonpressed.9.png")

SetNinePatchButton(Button1,"button","buttonpressed")

SetNinePatchButton(Button1,"button.9","buttonpressed.9")

The same problem.
 
Upvote 0
Top