Is there a way to appear bordered text on the TextView ?
Asked
Active
Viewed 2.0k times
5

Oak Bytes
- 4,649
- 4
- 36
- 53

AndroiDBeginner
- 3,571
- 11
- 40
- 43
-
Could you clarify what you mean by "bordered text"? – David Webb Jan 08 '10 at 10:30
-
Thanks response. I mean each letter of text would be bordered. How to make it ? Sorry for my bad English. – AndroiDBeginner Jan 10 '10 at 04:52
2 Answers
16
I would suggest to extend TextView
See Android Custom Component Guide
package samples.test;
public class MyTextView extends TextView {
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyTextView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Rect rect = new Rect();
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.WHITE);
paint.setStrokeWidth(3);
getLocalVisibleRect(rect);
canvas.drawRect(rect, paint);
}
}
Than use it in layout xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<samples.test.MyTextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello" />
</LinearLayout>

John Doe
- 15
- 4

Maksym Gontar
- 22,765
- 10
- 78
- 114
5
Most simple way is use a 9 patch background.
<TextView android:id="@+id/txt_target"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="000000000"
android:gravity="center_vertical"
android:background="@drawable/textfield_default"
android:layout_marginRight="5dip" />

Cytown
- 1,539
- 9
- 7