Android Question [Solved] EditText black border

malcolmfowler

Member
Licensed User
I would like to add a field to collect multi-line text data. i.e. EditText. I would like it to have a a black border. I followed a thread that suggested I need to load the Custom View library to achieve this however it is not available on the standard B4A system. (I did find xCustomListView).

So, could someone enlightened me as to how to create a bordered field to collect text data.

Thanks
 

MarkusR

Well-Known Member
Licensed User
maybe a panel behind with border width 1?
 
Upvote 0

Mahares

Expert
Licensed User
What about something simple like this or am I being very simplistic:
B4X:
Dim edt As EditText  'in Globals
    edt.SingleLine=False
    Dim cd As ColorDrawable
    cd.Initialize2(Colors.Red, 10dip,5dip,Colors.Black)
    edt.Background=cd
    edt.Text="This is a multi line edittext with a black border"
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
i wonder why is this Background property not in the designer?
 
Upvote 0

DonManfred

Expert
Licensed User
you also can have it a bit more complex. a different color for each state.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    addstatelist(EditText1)
    addstatelist(EditText2)
    addstatelist(EditText3)
End Sub
Sub addstatelist(edt As EditText)
    Dim jo As JavaObject = edt
    jo.RunMethod("setFocusableInTouchMode",Array As Object(True))
    jo.RunMethod("setFocusable",Array As Object(True))
    Dim focused, pressed, selected, disabled, enabled As ColorDrawable
    focused.Initialize2(Colors.Gray,5dip, 2dip, Colors.Black)
    pressed.Initialize2(Colors.DarkGray,5dip, 2dip, Colors.Blue)
    selected.Initialize2(Colors.Yellow,5dip, 2dip, Colors.Magenta)
    disabled.Initialize2(Colors.DarkGray,5dip, 2dip, Colors.Red)
    enabled.Initialize2(Colors.Black, 5dip, 2dip, Colors.Green)

    Dim sld As StateListDrawable
    sld.Initialize
    sld.AddState(sld.State_Focused, focused)
    sld.AddState(sld.State_Pressed, pressed)
    sld.AddState(sld.State_Selected, selected)
    sld.AddState(sld.State_Disabled, disabled)
    sld.AddState(sld.State_enabled, enabled)

    edt.Background = sld   
End Sub
 

Attachments

  • StateListEx.zip
    9.2 KB · Views: 248
Upvote 0
Top