首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

TextView添边框

2012-09-01 
TextView加边框package samples.test?public class MyTextView extends TextView {?? ? public MyTextVie

TextView加边框

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); ? ? ? ?
? ? }?
}?

?

<?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>

热点排行