Home > OS >  Android Edittext not updating height is first letter is a new line
Android Edittext not updating height is first letter is a new line

Time:09-22

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?

CodePudding user response:

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, int, int, int)

To either remove/ignore a newline at the start

or

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

CodePudding user response:

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

  • Related