带描边的TextView
来源:互联网 发布:mac动态壁纸 编辑:程序博客网 时间:2024/05/16 08:51
描边TextView
(1)在attrs.xml中添加StrokeText属性
<declare-styleable name="StrokeText"> <attr name="StrokeColor" format="reference|color"/> <attr name="TextColor" format="reference|color"/></declare-styleable>
(2)新建类继承TextView
public class StrokeTextView extends TextView{ private int strokeColor; private int textColor; public StrokeTextView(Context context){ super(context); } @SuppressLint("NewApi") public StrokeTextView(Context context,AttributeSet attrs,int defStyleAttr,int defStyleRes){ super(context,attrs,defStyleAttr) } public StrokeTextView(Context context,AttributeSet attrs,int defStyleAttr){ super(context,attrs,defStyleAttr) } public StrokeTextView(Context context,AttributeSet attrs){ super(context,attrs); TypedArray typeArray=context.obtainStyledAttributes(attrs,R.styleable.StrokeText); textColor=typeArray.getColor(R.styleable.StrokeText_TextColor,0XFFFFFFFF); strokeColor=typeArray.getColor(R.styleable.StrokeText_StrokeColor,0XFFFFFFFF); } @Override protected void onDraw(Canvas canvas){ //描外边 setTextColorUseReflection(strokeColor); getPaint().setStrokeWidth(3); getPaint().setStyle(Style.FILL_AND_STROKE); getPaint().setFakeBoldText(true); getPaint().setShadowLayer(1,0,0,0); super.onDraw(canvas); //描内边 setTextColorUseReflection(textColor); getPaint().setStrokeWidth(0); getPaint().setStyle(Style.FILL_AND_STROKE); getPaint().setFakeBoldText(false); getPaint().setShadowLayer(0,0,0,0); super.onDraw(canvas); } private void setTextColorUseReflection(int color){ Field textColorField; try{ textColorField=TextView.class.getDeclaredField("mCurTextColor"); textColorField.setAccessible(true); textColorField.set(this,color); textColorField.setAccessible(false); }catch(NoSuchFieldException e){ e.printStackTrace(); }catch(IllegalArgumentException e){ e.printStackTrace(); }catch(IllegalAccessException e){ e.printStackTrace(); } getPaint().setColor(color); }}
(3)layout.xml中调用
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myspace="http://schemas.android.com/apk/res/com.crelead.ordersys" android:layout_width="match_parent" android:layout_height="match_parent" > <com.rainbow.sys.view.StrokeTextView android:id="@+id/strokeText" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignLeft="@+id/textView" android:layout_alifnParentTop="true" android:text="StrokeTextView" myspace:StrokeColor="@color/black_color" myspace:TextColor="@color/golden_color" /> </RelativeLayout>
0 0
- 带描边的TextView
- android 自定义TextView"会发脾气的TextView"
- TextView-SpannableString(花哨的TextView)
- andorid TextView(1)-带图片的TextView
- 带icon的textview
- textview的颜色
- 自由选择TextView的文字
- TextView的文字剧中
- TextView的简单使用
- TextView闪烁的问题
- Textview的参数
- 控件TextView的用法
- TextView的文字设置
- 带图片的textview
- Textview的参数
- 一直滚动的TextView
- TextView的常用技巧
- 监听textview的变动
- 重庆静脉曲张治疗的方法
- 二维码开发,扫描,生成
- mongodb3.0 单机数据迁移 分片复制集
- iOS AutoLayout保证view在StatusBar下
- iOS开发中监听键盘状态、输入法状态
- 带描边的TextView
- 1-- 选择排序之简单选择排序
- java解析逻辑表达式
- Android的代码混淆————ProGuard
- shell循环和条件判断
- Go语言的fmt包中文教程 %s
- 批处理添加环境变量
- JavaWeb学习总结(五十)——文件上传和下载
- 使用struts时,There is no Action mapped for namespace的解决办法