Android Question EditText changing colour when touched

Yves Mazzon

Member
Licensed User
Longtime User
All,
I have a series of EditText boxes where I have to change the values from a soft keyboard. How can I highlight the EditText boxes individually when when they are touched or have focus either slightly change the colour or having a colour line around it? The colour should return to its initial stage when another one is touched. many thanks for your time.

Best regards,

Yves
 

DonManfred

Expert
Licensed User
Longtime User
Try this (using statelist drawables for each edittext
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private EditText1 As EditText
    Private EditText2 As EditText
    Private EditText3 As EditText
    Private EditText4 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
  Dim checked, unchecked As ColorDrawable
  checked.Initialize(Colors.Green, 10dip)
  'unchecked.Initialize(Colors.Red, 10dip)

  Dim sld As StateListDrawable
  sld.Initialize
  sld.AddState(sld.State_Focused, checked)
  EditText1.Background = sld
  Dim sld As StateListDrawable
  sld.Initialize
  sld.AddState(sld.State_Focused, checked)
  EditText2.Background = sld
  Dim sld As StateListDrawable
  sld.Initialize
  sld.AddState(sld.State_Focused, checked)
  EditText3.Background = sld
  Dim sld As StateListDrawable
  sld.Initialize
  sld.AddState(sld.State_Focused, checked)
  EditText4.Background = sld
End Sub

statelist1.png


statelist2.png
 

Attachments

  • statelist.zip
    7.4 KB · Views: 251
Upvote 0
Top