Buddy
Buddy

Reputation: 280

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?

Upvotes: 2

Views: 2978

Answers (2)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364694

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"

Upvotes: 2

Nagoor Bhasha
Nagoor Bhasha

Reputation: 66

create a drawable with shape rectangle and apply background to edit text

    <shape android:shape="rectangle">
        <stroke android:width="1dip" android:color="#4e555f" />
    </shape>


        <EditText
            android:id="@+id/sign_in_mobile_no"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="drawable name"/>

Upvotes: 1

Related Questions