B4J Question B4XFloatTextField Alignment reset after clicking on Reveal button

aeric

Expert
Licensed User
Longtime User
Using the code below, I can Center the alignment of text.
B4X: Copy
B4XFloatTextField.TextField.SetTextAlignment("CENTER", "CENTER")

For Password Field, when I click the reveal (eye) button, the alignment changed to Left.
However this does not happen when clicking on the clear (x) button.

How to stop the alignment change to Left?
 
Last edited:
Solution
Code: Copy
Private Sub B4XFloatTextField1_PasswordRevealChanged (Revealed As Boolean)
    Sender.As(B4XFloatTextField).TextField.SetTextAlignment("CENTER", "CENTER")
End Sub

It works fine. And the movement isn't noticeable in release mode.

java_ythJ1px30b.gif
How to stop the alignment change to Left?
will not be possible without customizing the class, as the text field will be rebuilt each time you switch.

But maybe @Erel will build in a property for this, so that this is taken into account when rebuilding.
 
Upvote 0
will not be possible without customizing the class, as the text field will be rebuilt each time you switch.

But maybe @Erel will build in a property for this, so that this is taken into account when rebuilding.
I just checked the source, it is indeed calling CreateTextFieldAll and CreateTextField after SwitchFromPasswordToRegular(ToRegular As Boolean).
 
Upvote 0
I just checked the source, it is indeed calling CreateTextFieldAll and CreateTextField after SwitchFromPasswordToRegular(ToRegular As Boolean).
I studied the soruce code when I developed my AS_TextFieldAdvanced and it stuck in my head 😀
 
Upvote 0
You should handle the PasswordRevealChanged event and set the alignment. It happens because the underlying text field is replaced with a new one.
I tried the following code:
B4X: Copy
Private Sub txtPinCode_PasswordRevealChanged (Revealed As Boolean)
    txtPinCode.TextField.SetTextAlignment("CENTER", "CENTER")
End Sub
The dots moves from left to center very quickly and disappeared.
 
Upvote 0
It happens because the text field is replaced and then the event is raised with CallSubDelayed. I don't think that you will be able to workaround it without modifying the source code. It is possible add B4XFloatTextField to your project and keep using XUI Views. You can then change the event to use CallSub instead of CallSubDelayed.
 
Upvote 0
Back
Top