美文网首页
Android带边框TextView

Android带边框TextView

作者: AppMonkey | 来源:发表于2018-03-05 12:10 被阅读0次
    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.support.v7.widget.AppCompatTextView;
    import android.util.AttributeSet;
    
    /**
     * Created by qinzhe on 2018/3/5.
     */
    
    public class BorderTextView extends AppCompatTextView {
    
        private int sroke_width = 1;
    
        public BorderTextView(Context context) {
            super(context);
        }
    
        public BorderTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public BorderTextView(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            Paint paint = new Paint();
            //  将边框设为灰色
            paint.setColor(Color.GRAY);
            //  画TextView的4个边
            canvas.drawLine(0, 0, this.getWidth() - sroke_width, 0, paint);
            canvas.drawLine(0, 0, 0, this.getHeight() - sroke_width, paint);
            canvas.drawLine(this.getWidth() - sroke_width, 0, this.getWidth() - sroke_width, this.getHeight() - sroke_width, paint);
            canvas.drawLine(0, this.getHeight() - sroke_width, this.getWidth() - sroke_width, this.getHeight() - sroke_width, paint);
            super.onDraw(canvas);
        }
    }
    

    相关文章

      网友评论

          本文标题:Android带边框TextView

          本文链接:https://www.haomeiwen.com/subject/rzthfftx.html