# TextView with border stroke

**URL:** <https://discourse.processing.org/t/textview-with-border-stroke/14570>\
**Category:** Processing for Android\
**Created:** [October 10, 2019, 11:51am UTC](https://discourse.processing.org/t/textview-with-border-stroke/14570 "2019-10-10T11:51:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [October 10, 2019, 11:51am UTC](https://discourse.processing.org/t/textview-with-border-stroke/14570/1 "2019-10-10T11:51:36Z")

</div>

Hi. I want a textView with a gray background, white text and a red border stroke.  
In the code below I get the border and text but the background becomes transparent.  
What is the right way to achieve this?

```auto
import android.app.Activity;
import android.widget.FrameLayout;
import android.graphics.Color;
import android.view.ViewGroup.LayoutParams;
import android.view.Gravity;
import android.R;
import android.graphics.Color;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.graphics.drawable.ShapeDrawable; 
import android.graphics.drawable.shapes.RectShape; 
import android.graphics.Paint.Style;

Activity act;
FrameLayout fl;

  public void onStart() {
  act = this.getActivity();

  ShapeDrawable sd = new ShapeDrawable(); 
  sd.setShape(new RectShape()); 
  sd.getPaint().setColor(Color.RED); 
  sd.getPaint().setStyle(Style.FILL);
  sd.getPaint().setStrokeWidth(10f); 
  sd.getPaint().setStyle(Style.STROKE); 
   
  TextView tv = new TextView(act);  
  tv.setLayoutParams(new RelativeLayout.LayoutParams(500, 100));
  tv.setBackground(sd);
  tv.setBackgroundColor(Color.GRAY);
  // tv.setBackground(sd);
  tv.setX(width/2-250);
  tv.setY(height/2);
  tv.setGravity(Gravity.CENTER);
  tv.setTextColor(Color.WHITE);
  tv.setTextSize(32);
  tv.setText ("Hello world");  
   
  fl = (FrameLayout)act.findViewById(R.id.content);
  FrameLayout.LayoutParams params1 = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
  fl.addView(tv);
}

void setup(){
  background(Color.BLUE);
}

```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [October 11, 2019, 7:06pm UTC](https://discourse.processing.org/t/textview-with-border-stroke/14570/2 "2019-10-11T19:06:38Z")

</div>

Well, here’s how.

```auto
import android.app.Activity;
import android.widget.FrameLayout;
import android.graphics.Color;
import android.view.ViewGroup.LayoutParams;
import android.view.Gravity;
import android.R;
import android.graphics.Color;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.graphics.Paint.Style;
import android.graphics.drawable.GradientDrawable;

Activity act;
FrameLayout fl;

public void onStart() {
  act = this.getActivity();

  GradientDrawable sd = new GradientDrawable(); 
  sd.setShape(GradientDrawable.RECTANGLE); 
  sd.setColor(Color.GRAY); 
  sd.setStroke(8, Color.RED); 

  TextView tv = new TextView(act);  
  tv.setLayoutParams(new RelativeLayout.LayoutParams(500, 100));
  tv.setBackgroundColor(Color.GRAY);
  tv.setBackground(sd);
  tv.setX(width/2-250);
  tv.setY(height/2);
  tv.setGravity(Gravity.CENTER);
  tv.setTextColor(Color.WHITE);
  tv.setTextSize(32);
  tv.setText ("Hello world");  

  fl = (FrameLayout)act.findViewById(R.id.content);
  FrameLayout.LayoutParams params1 = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
  fl.addView(tv);
}

void setup() {
  background(Color.BLUE);
}

```
