I am developing an Android app. I need to know how we can have a EditText with border. In Lolipop they have completely changed the EditText style. Can we do it without using drawables?
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code we have taken one text view with background as border so we need to create a file in drawable as boarder.
A EditText is an overlay over TextView that configures itself to be editable. It is the predefined subclass of TextView that includes rich editing capabilities.
Write editTextBackground.xml in drawable folder in resources
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:width="1dp" android:color="@color/borderColor" /> </shape>
don't forget to declare color in resources named borderColor
.
and assign this background to the EditText
in xml background attribute
<EditText android:id="@+id/text" android:background="@drawable/editTextBackground" />
and it'll set border to EditText
.
You can change border of edit text without drawable by using style
attribute
style="@style/Widget.AppCompat.EditText"
for more details visit customize edit text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With