how to change textfield background color programatically

305 views
Skip to first unread message

sri

unread,
Apr 9, 2014, 9:08:45 AM4/9/14
to codenameone...@googlegroups.com
hi am doing textfeild validation and when the user enters details and clicks submit 
 if user forgets sometextfields i want to show those text fields in red color 
 
i have tried 

textField.getStyle().setBackgroundGradientEndColor(Style.BACKGROUND_GRADIENT_LINEAR_HORIZONTAL, true);
textField.getStyle().setBackgroundGradientStartColor(0x202020, true);
textField.getStyle().setBackgroundGradientEndColor(0x7cfc00,true);
textField.getStyle().setBgImage(null); 
but field color dint change
 am i missing something ?

Shai Almog

unread,
Apr 9, 2014, 1:24:47 PM4/9/14
to codenameone...@googlegroups.com
Hi,
I suggest not using gradients. They are VERY inefficient! Usage image borders or images: http://www.codenameone.com/how-do-i---improve-application-performance-or-track-down-performance-issues.html

A text field has a border which takes precedence over gradient/bg-image so you would need to null it as well.
You should never use getStyle() and only use getUnselected/Selected/Pressed/Disabled() style.

A better approach would be:

textField.setUIID("InvalidTextField");

Then just style it in the designer.
Reply all
Reply to author
Forward
0 new messages