Consistent Appearance for EditText & Labels

devlei

Active Member
Licensed User
Longtime User
Input fields on a form include EditText & Label views. I would like both types of views to have a consistent appearance (background & text colors) for all Android versions (and/or devices).

The Labels' appearance I set from the Designer and they remain consistent, but the EditText's appearance is different across devices. I can't see how to set the EditText's appearance from the designer and could not find an example of how to set it by code.

Any assistance would be much appreciated!!
 

klaus

Expert
Licensed User
Longtime User
You could create your own 9 patch image and set it to the EditText views.

Attached a small test project, the image is taken from Erel's tutorial.
For more detatails you should read chapter 9.1.5 NinePatchDrawable in the User's Guide.
Unfortunately, the example program in the User's Guide Source Code doesn't work, the Object folder is missing.
I attached it below.

Best regards.
 

Attachments

  • EditText9Patch.zip
    6.9 KB · Views: 178
  • NinePatchExample.zip
    9.7 KB · Views: 145
Upvote 0

devlei

Active Member
Licensed User
Longtime User
Thank you for the response,Klaus.

I had hoped it would be simpler. Is it not possible to just set the EditText.Background property via code? If so, is there an example somewhere?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You can do it with this code:
B4X:
EditText2.Initialize("EditText2")
Activity.AddView(EditText2, 50dip, 70dip, 150dip, 50dip)
Dim cdw As ColorDrawable
cdw.Initialize(Colors.White, 5dip)
EditText2.Background = cdw
I proposed you the 9path image because it is much more versatile and could have something similar to the older EditText view background.

Best regards.
 
Upvote 0

devlei

Active Member
Licensed User
Longtime User
Thanks, Klaus, this example is exactly what I was looking for. I have subsequently also found it in your User Guide in section 9.

Your help is much appreciated!!!
 
Upvote 0
Top