How to change background color of a native.textfield

I’m trying to create an input native textfield but I didn’t want that white field appearing, only the text my user would type in.

I know that we can set background as false for native.textBox, but I wanted to restrict the input type to number, so I guess I would have to stick to textField.
I read a blog post from ansca a while ago stating that both could set the background color.

how can I do that?
tried object:setFillColor(), but the code halted.
[import]uid: 125498 topic_id: 22156 reply_id: 322156[/import]

You’d likely set obj.hasBackground = false and then simply display the background color/image you want in the position of the field. [import]uid: 52491 topic_id: 22156 reply_id: 88302[/import]

can I do that for native Text Field (not text box) ?

I just want the original black background to show instead of the opaque white background (of the text field), so in this case I don’t need to set a image or rectangle beneath the text field, do I ?
edit:

Just ran a test here, with the code

[lua]local myTextField = native.newTextField(30, 30, 50, 50)
myTextField.text = “testing”
myTextField.hasBackground = false
local rectang = display.newRect(15,15,280,150)
rectang:setFillColor(255,0,255)[/lua]

and the textfield background still shows up, above the fuchsia rectangle.
[import]uid: 125498 topic_id: 22156 reply_id: 88394[/import]

Is this test in the Corona simulator or on Xcode sim/device? For this you would need to test on Xcode sim/device, not Corona sim.

Can you try that and let me know results, please? I believe it should work :slight_smile: [import]uid: 52491 topic_id: 22156 reply_id: 88415[/import]

tested on iphone 2g, didn’t work.

screenshot from my device

http://img715.imageshack.us/img715/67/coronax.jpg

yesterday I tried switching to textBox, and it worked (and it is as u said, only device, simulator wouldn’t get the background off), but as I want to restrict the input to numbers only and textBox doesn’t allow me to do that, I have to stick to textField.

(also, I couldn’t find a way to make the multiline textBox non-scrollable, any commands for that?)

thanks for all the help! [import]uid: 125498 topic_id: 22156 reply_id: 88424[/import]

iPhone 2g is quite old and I’m guessing running an older iOS as well.

Do you have a newer device to test on? Or Xcode simulator? I just used your code and works in Xcode simulator.

Apple isn’t supporting builds for the iPhone 3g and below soon and it would be good to test on a device running iOS 4.3.0 or above. [import]uid: 52491 topic_id: 22156 reply_id: 88576[/import]

The docs do need updating in parts, definitely - will add this to the list.

For the older phone stuff we will have that up somewhere when the time comes - right now you can still build for it using the latest, stable release, it’s just that in the future this wont be the case. (Daily builds have dropped support for < 3GS on 4.3.0.)

For now the border can’t be removed as far as I know but there are some workarounds if it’s important to you, see here; http://developer.anscamobile.com/forum/2012/01/09/remove-border-around-textfield

Depending on what you are doing a rounded rectangular background could look very nice. (That obviously depends on the app, though.)

No worries RE the help :slight_smile: [import]uid: 52491 topic_id: 22156 reply_id: 88659[/import]

oh…tried running on xcode simulator and it indeed worked…

I guess it is finally for me to upgrade my mobile device, at last. lol
Peach, is there any way to get the border off too? the white background disappeared, but I still see a translucent border above the background color. It already helps a lot, but that little tweak would make it perfect for my needs.

also, I believe that this info should be on the docs as well.

http://developer.anscamobile.com/reference/index/nativenewtextfield

native text field documentation doesn’t state anything about .hasBackground, the only reference I found was from a blog post stating the differences and common stuff from text field and text box.

And also the information about it not working on iphone 2g * might * be a good addition as well. I know that the 2g is only about 5% of the entire market, but I’m sure that there are people over there developing for it.

Once more, thanks Peach! You’ve been helping me a lot lately!

[import]uid: 125498 topic_id: 22156 reply_id: 88637[/import]