Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have EditText with border in Android Lollipop

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?

like image 229
Sumanth Jois Avatar asked Mar 03 '16 02:03

Sumanth Jois


People also ask

How do you add a border to text on Android?

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.

What is EditText?

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.


1 Answers

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.

UPDATE

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

like image 78
ELITE Avatar answered Sep 27 '22 21:09

ELITE