How to add a border in a TextView by code?

2

I'm doing a dynamic form and would like to add an embroidery around a set with a TextView and an EditText like in the code below:

TextView tv = new TextView(this);
        tv.setText(vet[0]);

        EditText et = new EditText(this);
        et.setSingleLine();
        et.setText("");

I would like to put this content in a very simple border, as it is possible in a very simple way

    
asked by anonymous 17.07.2015 / 21:14

1 answer

3

VIA .XML

I created an .xml file

<?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="2dp"
        android:color="sua cor" />

</shape>

With this you can apply within your TextView a "background" that is actually a border.

<TextView
      android:background="@drawable/text_view_border" />

Via code:

et.setBackgroundDrawable(new Border("cor","espessura));
    
17.07.2015 / 21:21