title: dynamically replace EditText in TextInputLayout with another EditText
body: <p>I'm using TextInputLayout to show some input, somewhere in my code I want to replace the EditText with another EditText but when I do this design of the input gets messy. My code looks like this:</p>
  
  <pre><code>&lt;com.google.android.material.textfield.TextInputLayout
      android:id="@+id/generalInputLayout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:boxStrokeColor="@color/colorAccent"
      app:boxStrokeWidth="1dp"
      android:theme="@style/InputLayoutStyle"
      style="@style/InputLayoutStyle"
      android:background="@drawable/input_border"
      &gt;
  
      &lt;EditText android:id="@+id/oldEditText"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:hint="شماره موبایل"
          android:paddingBottom="@dimen/space_1"
          android:background="@android:color/transparent"
          xmlns:android="http://schemas.android.com/apk/res/android" /&gt;
  
  &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  </code></pre>
  
  <p>And I use this code to replace the edit text</p>
  
  <pre><code>    val parentOfEditText = oldEditText.parent as ViewGroup
      val index = parentOfEditText.indexOfChild(oldEditText)
      layoutParams = oldEditText.layoutParams
      parentOfEditText.removeView(oldEditText)
      inputET.layoutParams = layoutParams
      parentOfEditText.addView(inputET, index)
  </code></pre>
  
  <p>The result looks like this. the bottom input is how it should be (before replace) and the top one is after replace. But I can't figure out why this happens. BTW the exact the same view is used for replacing so the edit text is not changing. </p>
  
  <p><a href="https://i.stack.imgur.com/SG1jO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SG1jO.png" alt="enter image description here"></a></p>