Friday, March 6, 2015

How to set border on EditText or TextView

To set border to a text widget, create an xml file (border.xml) with following content:
res/drawable/border.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/transparent"/>
    <stroke
        android:width="1dp"
        android:color="#333333"/>
</shape>
Note: Create drawable folder inside res, if it's not already there.

After that, set this new drawable as background resource for your editText or TextView widget
<TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@drawable/border"
/>

No comments:

Post a Comment