方法一:
比较土 ,加背景图片,透明的带边框的背景图片
设置到android:background就可以
方法二:¸创建一个 shape 设置到android:background就可以
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00000000"/>
<stroke android:width="2dip" android:color="#ff000000" />
</shape>
方法三:
编写一个继承TextView类的自定义组件,并在onDraw事件方法中画边框。
然后 在布局文件 中 使用 自定义 textview 即可
public class BorderTextView extends TextView{
public BorderTextView(Context context) {
super(context);
}
public BorderTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
private int sroke_width = 1;
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
// 将边框设为黑色
paint.setColor(android.graphics.Color.BLACK);
// 画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:background就可以
方法二:¸创建一个 shape 设置到android:background就可以
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00000000"/>
<stroke android:width="2dip" android:color="#ff000000" />
</shape>
方法三:
编写一个继承TextView类的自定义组件,并在onDraw事件方法中画边框。
然后 在布局文件 中 使用 自定义 textview 即可
public class BorderTextView extends TextView{
public BorderTextView(Context context) {
super(context);
}
public BorderTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
private int sroke_width = 1;
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
// 将边框设为黑色
paint.setColor(android.graphics.Color.BLACK);
// 画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);
}
}