Android Question [NOT RESOLVED] Padding not honored for B4XFloatTextField

mfstuart

Active Member
Licensed User
Longtime User
I followed this post https://www.b4x.com/android/forum/threads/padding-doesnt-work-in-b4xfloattextfield.133236/
and added the code to the B4XPage_Created event.

B4X:
    Dim edt1 As EditText = txtUser.TextField
    edt1.Padding = Array As Int (20dip, 0dip, 0dip, 0dip)
    
    Dim edt2 As EditText = txtPassword.TextField
    edt2.Padding = Array As Int (20dip, 0dip, 0dip, 0dip)

Layout setup:
In the Designer, placed 2 B4XFloatTextFields on a layout: txtUserName, txtPassword.
Set the Hint Text for both: User Name, Password (no leading spaces).
No Padding property value for both.
For txtPassword, the Password Field property is checked.

Observations:
1. When running the app in Debug mode, the Hint Text is shown to the far left and the Padding is not honored, therefore when the cursor is placed in the field, the cursor is in-between the first and second characters. Not good.
2. When text is typed in (both fields), the Hint goes to the top - as it should - and the typed in text is displayed correctly - the Padding is honored.
3. For the txtPassword field, when the "eye" reveal button is clicked, the actual text is displayed hard left in the text field. Not expected. The Padding should still be honored. When the "eye" reveal button is clicked again the text is hidden and the dots appear hard left of the text field.

It seems the Padding, whether as a Property or in code is not fully honored/working.

Can this be fixed, or am I doing something wrong?

Thanx,
Mark Stuart
 

mfstuart

Active Member
Licensed User
Longtime User
I would like to suggest that the Padding property be removed based on your answer for no built-in padding for a B4XFloatTextField.
Especially when the behavior is not what is expected.
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Can you disable those property fields that are not valid for a view?
Because it is quite misleading to a developer to expect a property to work, and it doesn't. Hence this post is a waste of time.
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
OK, thanx.
Currently, I unzipped the XUI Views.b4xlib and reading the B4XFloatTextField.bas file.
Trying to find some resemblance of fixing this issue or a better work-around.
If you open the ThreePagesExample B4A app and play around with the padding, such as:
B4X:
    Dim edt1 As EditText = txtUser.TextField
    edt1.Padding = Array As Int (20dip, 0dip, 0dip, 0dip)

or this:
B4X:
txtUser.TextField.As(EditText).Padding = Array As Int(20dip,0dip,0dip,0dip)

and set the Hint Text, and run the app, then place the cursor in the User Name field, the cursor is placed in-between the 1st and 2nd character - not acceptable.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Try this code:
B4X:
    B4XFloatTextField1.TextField.Left = 10dip
    B4XFloatTextField1.HintLabelSmallOffsetX = 10dip
    B4XFloatTextField1.HintLabelLargeOffsetX = 15dip
    B4XFloatTextField1.Update
Example is attached
 

Attachments

  • B4XFloatTextField Padding.zip
    9.3 KB · Views: 150
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Alexander, thank you for your help. A modified version of your code example worked for me...
B4X:
    Dim edt1 As EditText = txtUser.TextField
    edt1.Padding = Array As Int (20dip, 0dip, 0dip, 0dip)
    'txtUser.TextField.Left = 20dip        <=== pushes the actual input TextField to the right too far. Not desired.
    txtUser.HintLabelSmallOffsetX = 20dip
    txtUser.HintLabelLargeOffsetX = 20dip
    txtUser.Update
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Now, if this code could be added/modified into the "XUI View" - B4XFloatTextField.bas, based on the following condition:

If the B4XFloatTextField "Hint Text" property has a value, then apply the above code, AND if the Padding property is populated.
I don't know if that's possible, but would surely resolve some developer and end-user frustration.

Thanx,
Mark Stuart
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
HOLD ON!

I added another B4XFloatTextField view to the layout: txtPassword. Checked the "Password Field" and "Show Reveal Button" check boxes.

Added my above code to handle the padding. When running the app, works as expected.
But when the "reveal" button is pressed, the padding is lost and the text is "pushed/aligned" to the far left. Not expected.

So is there code for the Reveal button that maintains/keeps the Padding?
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
If the B4XFloatTextField "Hint Text" property has a value, then apply the above code, AND if the Padding property is populated.
I don't know if that's possible, but would surely resolve some developer and end-user frustration.
B4X:
    If B4XFloatTextField1.TextField.As(EditText).Padding(0) = 20dip And B4XFloatTextField1.HintText <> "" Then
        Log("Do something")
    End If
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
But when the "reveal" button is pressed, the padding is lost and the text is "pushed/aligned" to the far left. Not expected.
This is because the view then recreates the TextField and thus all settings made outside the view are reset.
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
To me, this is still a bug that needs to be fixed.
Until @Erel applies a fix, I'm going back to regular TextField views!

Thanx,
Mark Stuart
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
To me, this is still a bug that needs to be fixed.
This is not a bug, it is intentional.

Since I recently created a TextField view, I know why Erel chose this method. It is not possible on all 3 platforms to change the native textfield to password mode while running.
I solved this by having 2 textfields that disappear into the background or foreground depending on which mode you are in.
 
Upvote 0
Top