skip to Main Content

Android Edittext not updating height is first letter is a new line. However, even if I press a letter and then press newlines, it starts to work.

Also, if I am typing a long line, it is working fine as well.
How can I fix it?

2

Answers


  1. Sounds like an edge case, I’ll just assume that your app is in the 90% of apps where a new line at the start of the EditText is not something you want anyways. In that case you can use callbacks like beforeTextChanged:

    https://developer.android.com/reference/android/text/TextWatcher#beforeTextChanged(java.lang.CharSequence,%20int,%20int,%20int)

    To either remove/ignore a newline at the start

    or

    replace one n with nn (2 newlines, which should increase the height, but not 100% sure)

    Login or Signup to reply.
  2. As Per Your Question you have to set a EditText As per Your Situation.In Normal Edittext code is as below.

    <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            //Other Data Goes Here
        />
    

    If you want to set a height of you edittext is long then you want to code as below

    <EditText
            android:layout_width="match_parent"
            android:layout_height="50dp"
            //Other Data Goes Here
        />         
    

    you can change the layout height as per your Choice

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search