Android Question Edit Text cursor

iCAB

Well-Known Member
Licensed User
Longtime User
Hi All,

I found the post below while looking for a solution to make the edit text cursor visible on newer android devices :
Make Edittext cursor more visible[Solved]

Does this mean, we need to edit the manifest file to include every EditText control on every data entry form?

Is there a cleaner way, for fixing this in code?

Thanks,
iCAB
 

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Erel,

Thanks for your reply.

Sorry, a bit slow here :(. Can you please help with the syntax.

Say I already have 2 EditText boxes that are added previously in code and as follows:

B4X:
    Dim et1 As EditText
    Dim et2 As EditText

    Activity.AddView(et1, 50%x -100dip, 100dip, 200dip, 50dip)
    Activity.AddView(et2, 50%x -100dip, 150dip, 200dip, 50dip)

The sample code for the XMLLayoutbuilder shows that a control (et3) can be added as follows:
B4X:
    Dim x As XmlLayoutBuilder
    x.LoadXmlLayout(Activity, "layout1")
    Dim et3 As EditText = x.GetView("edittext1")
    et3.Tag = "test2"'
    et3.RemoveView
    
    Activity.AddView(et3, 50%x -100dip, 200dip, 200dip, 50dip)


How to apply edittext1 style/formatting to et1 & et2

Thanks in advance!
iCAB
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
You need to call LoadXmlLayout multiple times.

Hi Erel,
You already mentioned that but I am need clear about the syntax.

Please add the syntax below my comment at the end of the code


B4X:
Sub Activity_Create(FirstTime As Boolean)
    
    Activity.LoadLayout("Layout1")   
    
    'Load Custom EditText .....
    Dim x As XmlLayoutBuilder
    x.LoadXmlLayout(Activity, "mycustomlayout")
    Dim et As EditText = x.GetView("customedittext1")  'customedittext1 defined in the manifest ...
    et.RemoveView
    
    Activity.AddView(et, 50%x -100dip, 10%y, 200dip, 50dip)
    
    'Add border to the EditText
    Dim cd As ColorDrawable
    cd.Initialize2 (Colors.White, 5dip, 2dip, Colors.Red)
    et.Background = cd
    
    
    Dim edtText1 As EditText
    Dim edtText2 As EditText
    
    edtText1.Initialize("edtText1")
    edtText2.Initialize("edtText2")

    Activity.AddView(edtText1, 50%x -100dip, 20%y, 200dip, 50dip)
    Activity.AddView(edtText2, 50%x -100dip, 30%y, 200dip, 50dip)

    Dim x1 As XmlLayoutBuilder
    x1.LoadXmlLayout(Activity, "mycustomlayout")

    ' How to apply X1 to edtText1 & edtText2
    ' Please fill the code below
    

End Sub

Thank you
iCAB
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1667195954170.png


Please add the syntax below my comment at the end of the code
I cannot waste my time with activities. Sorry.

Here is a B4XPages example:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Panel3 As B4XView
    Private Panel2 As B4XView
    Private Panel1 As B4XView
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Panel1.AddView(CreateEditText, 0, 0, Panel1.Width, Panel1.Height)
    Panel2.AddView(CreateEditText, 0, 0, Panel2.Width, Panel2.Height)
    Panel3.AddView(CreateEditText, 0, 0, Panel3.Width, Panel3.Height)
End Sub

Private Sub CreateEditText As B4XView
    Dim x As XmlLayoutBuilder
    x.LoadXmlLayout(B4XPages.GetNativeParent(Me), "layout1")
    Dim et As EditText = x.GetView("edittext1")
    et.RemoveView
    Return et
End Sub
 
Upvote 0

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Erel,

Thanks for your reply, but I wasn't trying to waste anyone's time.

Perhaps my question in the first Post wasn't clear, that's why I posted the code in Post#3 to clarify what I was trying to achieve. And since the answer provided in Post#4 was not applicable to Post#3, I followed up with another example in Post#5 hoping to make it more clear. Unfortunately the code in Post#6 doesn't answer my question either.

I am simply looking for a way to apply similar cursor formatting as in your example, to existing editText boxes that were previously added in code as in Posts #3 & #5 without having to change the full code.

Is it possible?

Thanks,
iCAB
 
Upvote 0
Top