Keyboard suggestions cause part of Android EditText.setError() message to not display

前端 未结 5 1438
迷失自我
迷失自我 2020-12-09 05:14

When I\'m using edittext.setError(\"enter a comment\") in android, it works fine until the keyboard suggestions come up and the error gets pushed above the

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 05:53

    @Andy Lobel: I also faced this issue and have to fix it by putting on white-spaces(10-12) at the end of the text, so truncation happened only to white-spaces :) Also, my setError looked better by making setError text and EditText aligned.

    Other Case: I was stuck on an another issue wherein, drawable icon is displayed but that floating message and its rectangular box didn't appear.

    My Layout contained:

    1) Username Edit Text

    2) Password Edit Text

    3) Confirm Password Edit Text

    4) Register Button

    So, I was validating and showing error at the time of click on Register Button but found out that the message failed to appear and only drawable used to come and found that message will appear only when the Edit Text is focusable as:

    According to setError API Description:- Sets the right-hand compound drawable of the TextView to the "error" icon and sets an error message that will be displayed in a popup 'when the TextView has focus'.

    So, message was for UserName Edit Text but last focus remained on Confirm Password Edit text, so, it never showed up

    The solution/tweak for such case would be to:

    EditText.setFocusableInTouchMode(true);
    EditText.requestFocus();
    EditText.setError("My Error Text");
    

    Note: Wrote, just in case you are stuck on this point though other solutions might be available and sorry for so many editings as this is the best possible solution I came at last.

提交回复
热议问题