Search code examples
androidandroid-studioandroid-textinputlayout

How to create rectangular box around edittext in Android Studio


I want to create an attractive UI. I want to create a rectangular box around the edittext. How can I make it?


Solution

  • Just use the standard TextInputLayout with an OutlinedBox style:

         <com.google.android.material.textfield.TextInputLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
    
             <com.google.android.material.textfield.TextInputEditText
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:text="TEXT"/>
    
         </com.google.android.material.textfield.TextInputLayout>
    

    enter image description here

    You can use the boxStrokeWidth and boxStrokeColor to change width and color.

         <com.google.android.material.textfield.TextInputLayout
             app:boxStrokeColor="@color/xxxx"
             app:boxStrokeWidth="2dp"