Search code examples
androidandroid-edittexttextfieldandroid-custom-view

How to create outlined EditText in android?


I would like to customise textfield in Android.

When login activity shows up it will display normal text field as shown below:

Text field when login activity loaded

When user clicks on text field to input, text field should be displayed as:

Text field when user click to input

How can I achieve this behaviour?


Solution

  • You should try with Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense

        <com.google.android.material.textfield.TextInputLayout
                        style="@style/customInputLayoutStyle"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        >
    
                        <androidx.appcompat.widget.AppCompatEditText
                             android:layout_width="match_parent"
                             android:layout_height="wrap_content"
                             android:hint="Enter your valid phone" />
    
      </com.google.android.material.textfield.TextInputLayout>
    

    Then your customInputLayoutStyle will be

    <style name="customInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
            <item name="boxStrokeColor">@color/colorPrimary</item>
     </style>