P PeterPetSil Member Licensed User Longtime User Apr 20, 2012 #1 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:
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:
Erel B4X founder Staff member Licensed User Longtime User Apr 20, 2012 #2 See this tutorial: Nine patch images tutorial Upvote 0
P PeterPetSil Member Licensed User Longtime User Apr 20, 2012 #3 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
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.
P PeterPetSil Member Licensed User Longtime User Apr 21, 2012 #4 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: Code: Copy 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
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: Code: Copy 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_.]
thedesolatesoul Expert Licensed User Longtime User Apr 21, 2012 #5 Remove the '.png' from the SetNinePatch sub call. Sent from my GT-I9000 using Tapatalk Upvote 0
corwin42 Expert Licensed User Longtime User Apr 21, 2012 #6 PeterPetSil said: 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_.] Click to expand... Use lowercase names for the files Upvote 0
PeterPetSil said: 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_.] Click to expand... Use lowercase names for the files
P PeterPetSil Member Licensed User Longtime User Apr 21, 2012 #7 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 Click to expand... The same thing happens if I use SetNinePatchButton2() function. Last edited: Apr 21, 2012 Upvote 0
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 Click to expand... The same thing happens if I use SetNinePatchButton2() function.
Erel B4X founder Staff member Licensed User Longtime User Apr 22, 2012 #8 Can you upload your project (File - Export as zip)? Upvote 0
P PeterPetSil Member Licensed User Longtime User Apr 22, 2012 #9 Erel said: Can you upload your project (File - Export as zip)? Click to expand... It is attached. Peter Attachments 9Patch.zip 9Patch.zip 7.5 KB · Views: 410 Upvote 0
Erel said: Can you upload your project (File - Export as zip)? Click to expand... It is attached. Peter
Erel B4X founder Staff member Licensed User Longtime User Apr 22, 2012 #10 You should remove the .png extension. The layout file doesn't seem to include a view named Button1. Upvote 0
P PeterPetSil Member Licensed User Longtime User Apr 22, 2012 #11 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: Code: Copy 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
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: Code: Copy 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:
Erel B4X founder Staff member Licensed User Longtime User Apr 22, 2012 #12 If you are adding the button in the designer then you do not need to initialize it and add it in code. If it still doesn't work then please post your project. Upvote 0
If you are adding the button in the designer then you do not need to initialize it and add it in code. If it still doesn't work then please post your project.
P PeterPetSil Member Licensed User Longtime User Apr 23, 2012 #13 This is so wierd... I created another project, from scratch at another PC. I receive the same error: I removed the png extension from the code, but it is the same. Attached is the new project. Attachments 9Patch.zip 9Patch.zip 7.6 KB · Views: 401 Upvote 0
This is so wierd... I created another project, from scratch at another PC. I receive the same error: I removed the png extension from the code, but it is the same. Attached is the new project.
bluejay Active Member Licensed User Longtime User Apr 23, 2012 #14 According to the tutorial Erel referred to in post #2 the image files should have names ending in '.9.png'. BlueJay Upvote 0
According to the tutorial Erel referred to in post #2 the image files should have names ending in '.9.png'. BlueJay
P PeterPetSil Member Licensed User Longtime User Apr 23, 2012 #15 bluejay said: According to the tutorial Erel referred to in post #2 the image files should have names ending in '.9.png'. BlueJay Click to expand... Thanks for the hint. I renamed files tu .9.png in /res/drawable folder and then I tested it with different variations in code: Code: Copy SetNinePatchButton(Button1,"button.9.png","buttonpressed.9.png") SetNinePatchButton(Button1,"button","buttonpressed") SetNinePatchButton(Button1,"button.9","buttonpressed.9") The same problem. Upvote 0
bluejay said: According to the tutorial Erel referred to in post #2 the image files should have names ending in '.9.png'. BlueJay Click to expand... Thanks for the hint. I renamed files tu .9.png in /res/drawable folder and then I tested it with different variations in code: Code: Copy SetNinePatchButton(Button1,"button.9.png","buttonpressed.9.png") SetNinePatchButton(Button1,"button","buttonpressed") SetNinePatchButton(Button1,"button.9","buttonpressed.9") The same problem.
Erel B4X founder Staff member Licensed User Longtime User Apr 23, 2012 #16 You should try to follow our answers. As we wrote in post #5 and post #9 you should not include the png extension. It is also explained in the tutorial. Upvote 0
You should try to follow our answers. As we wrote in post #5 and post #9 you should not include the png extension. It is also explained in the tutorial.
thedesolatesoul Expert Licensed User Longtime User Apr 23, 2012 #17 If you renamed the files it also worth cleaning the project. Tools => Clean Project Upvote 0
P PeterPetSil Member Licensed User Longtime User Apr 23, 2012 #18 thedesolatesoul said: If you renamed the files it also worth cleaning the project. Tools => Clean Project Click to expand... Clean Project worked! Thanks guys! Upvote 0
thedesolatesoul said: If you renamed the files it also worth cleaning the project. Tools => Clean Project Click to expand... Clean Project worked! Thanks guys!