1 package com.example.furt.myapplication;
3 import android.content.Context;
4 import android.graphics.Canvas;
5 import android.graphics.Color;
6 import android.graphics.Paint;
7 import android.util.AttributeSet;
8 import android.widget.TextView;
10 public class BorderedTextView extends TextView {
11 private Paint paint = new Paint();
12 public static final int BORDER_TOP = 0x00000001;
13 public static final int BORDER_RIGHT = 0x00000002;
14 public static final int BORDER_BOTTOM = 0x00000004;
15 public static final int BORDER_LEFT = 0x00000008;
16 private Border[] borders;
18 public BorderedTextView(Context context, AttributeSet attrs, int defStyle) {
19 super(context, attrs, defStyle);
23 public BorderedTextView(Context context, AttributeSet attrs) {
24 super(context, attrs);
28 public BorderedTextView(Context context) {
33 paint.setStyle(Paint.Style.STROKE);
34 paint.setColor(Color.BLACK);
35 paint.setStrokeWidth(4);
38 protected void onDraw(Canvas canvas) {
40 if(borders == null) return;
41 for(Border border : borders){
42 paint.setColor(border.getColor());
43 paint.setStrokeWidth(border.getWidth());
45 if(border.getStyle() == BORDER_TOP){
46 canvas.drawLine(0, 0, getWidth(), 0, paint);
48 if(border.getStyle() == BORDER_RIGHT){
49 canvas.drawLine(getWidth(), 0, getWidth(), getHeight(), paint);
51 if(border.getStyle() == BORDER_BOTTOM){
52 canvas.drawLine(0, getHeight(), getWidth(), getHeight(), paint);
54 if(border.getStyle() == BORDER_LEFT){
55 canvas.drawLine(0, 0, 0, getHeight(), paint);
60 public Border[] getBorders() {
64 public void setBorders(Border[] borders) {
65 this.borders = borders;