自定义圆角TextView 背景色
2017-03-18 15:36
246 查看
在开发工程中可能会写很多不同颜色 倒角的shape 作为TextView 或Button的北京实现倒角的效果
管理先来张图
代码如下:
只是在OnDraw方法中画了一个圆角矩形 切记在super之前画
自定义两个属性 :
用法如下:
管理先来张图
代码如下:
package com.yighao.secondcar.secondHandCar.customView; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.RectF; import android.util.AttributeSet; import android.widget.TextView; import com.yighao.secondcar.R; import com.yighao.secondcar.secondHandCar.utils.DensityUtils; /** * Created by Administrator on 2017/2/16 0016. */ public class CirButton extends TextView { private Paint mPaint; private int radiu; public CirButton(Context context) { super(context); } public CirButton(Context context, AttributeSet attrs) { super(context, attrs); mPaint = new Paint(); mPaint.setDither(true); mPaint.setAntiAlias(true); mPaint.setStrokeWidth(5); mPaint.setStyle(Paint.Style.FILL); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.cir_button); int resourceId = typedArray.getResourceId(R.styleable.cir_button_cirColor, R.color.blue); int color = context.getResources().getColor(resourceId); mPaint.setColor(color); int integer = typedArray.getInteger(R.styleable.cir_button_cirRadiu, 10); radiu = DensityUtils.dp2px(context, integer); typedArray.recycle(); } @Override protected void onDraw(Canvas canvas) { RectF rectF = new RectF(0, 0, getMeasuredWidth(), getMeasuredHeight()); canvas.drawRoundRect(rectF, radiu, radiu, mPaint); super.onDraw(canvas); } }
只是在OnDraw方法中画了一个圆角矩形 切记在super之前画
自定义两个属性 :
<resources> <declare-styleable name="cir_button"> <attr name="cirColor" format="reference" /> <attr name="cirRadiu" format="reference|integer" /> </declare-styleable> </resources>
用法如下:
<com.yighao.secondcar.secondHandCar.customView.CirButton android:layout_width="100dp" android:layout_height="40dp" android:layout_marginLeft="30dp" android:layout_marginTop="30dp" android:gravity="center" android:text="adgdgg" app:cirColor="@color/orange" 背景颜色 app:cirRadiu="10" /> 倒角大小 单位为dp
相关文章推荐
- Android自定义TextView 自定义设置圆角背景色
- AndroidのTextView背景色、圆角、内部填充设置样式
- [置顶] android自定义view控件之一圆角背景TextView
- Android Shape Drawable Resources TextView渐变 背景色 圆角
- 自定义圆角点击变色TextView
- (转)Android TextView背景色、圆角、内部填充设置
- Android Shape Drawable Resources TextView渐变 背景色 圆角
- TextView属性设置背景色圆角字体大小
- 自定义支持圆角的TextView
- 001-自定义视图-圆角TextView、ImageView、Button
- android xml实现TextView圆角 边框颜色 边框长度 背景色
- Android TextView背景色、圆角、内部填充设置
- Android自定义TextView实心圆角颜色背景(动态改变圆角背景颜色)
- 自定义Dialog,带textview,EditText,Button
- 新书内容连载(1):自定义Android组件之带图像的TextView
- 自定义Android组件之带图像的TextView
- Android中为TextView增加自定义的HTML标签
- 一个自定义的android TextView控件例子
- Android自定义TextView中的超链接点击事件处理
- 实现TextView圆角效果