消息提醒---带阴影的圆形小球
2018-02-13 11:36
260 查看
自定义的属性
java代码
使用:
效果:
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="RedDotTextView"> <attr name="shadowWidth" format="dimension" /> <attr name="circleBackground" format="reference|color" /> </declare-styleable> </resources>
java代码
public class RedDotTextView extends AppCompatTextView { private Paint mPaint; private RectF mBgRect; private int mShadowWidth; private int mBgColor; public RedDotTextView(Context context) { super(context); init(context, null); } public RedDotTextView(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); } public RedDotTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context, attrs); } private void init(Context context, AttributeSet attrs){ if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RedDotTextView, 0, 0); try { if (a.hasValue(R.styleable.RedDotTextView_shadowWidth)) { mShadowWidth = a.getDimensionPixelSize(R.styleable.RedDotTextView_shadowWidth, -1); } if (a.hasValue(R.styleable.RedDotTextView_circleBackground)) { mBgColor = a.getColor(R.styleable.RedDotTextView_circleBackground, 0); } } finally { a.recycle(); } } mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); mPaint.setAntiAlias(true); mPaint.setColor(mBgColor); mPaint.setShadowLayer(1, 0, mShadowWidth, Color.parseColor("#7f565656")); setLayerType(LAYER_TYPE_SOFTWARE, mPaint); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); int width = getWidth(); mBgRect = new RectF(0, 0, width, width); } @Override protected void onDraw(Canvas canvas) { canvas.drawArc(mBgRect, 0, 360, false, mPaint); super.onDraw(canvas); } }
使用:
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.test.reddottextview.MainActivity"> <com.test.reddottextview.RedDotTextView android:layout_width="50dp" android:layout_height="51dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:shadowWidth="1dp" app:circleBackground="@color/colorAccent" android:text="hello" android:gravity="center"/> </android.support.constraint.ConstraintLayout>
效果:
相关文章推荐
- canvas标签(1)--线条、矩形、圆形、文本、阴影、抛小球
- QQ消息提醒小球OC 详解
- 圆形头像上右上角消息提醒数字
- js中的3种弹出式消息提醒(警告窗口,确认窗口,信息输入窗口)的命令式
- QQ群消息:友情提醒。
- java实现即时消息提醒方法
- BadgeView微信消息数字提醒
- android 桌面快捷键未读的消息数目,未接来电,短信提醒那个右上角的数字
- jQuery 消息插件--仿QQ消息弹出提醒
- 语音消息以及未读提醒连续播放
- 安卓应用在后台运行时,通知栏收到应用消息提醒时取消铃声和震动
- express redis socket 消息提醒方案:本地emit 轮循服务器获取redis 再推送
- Windows Phone 实用开发技巧(18):使用SystemTray显示全局消息提醒
- 开发服务社免费ERP的RTX消息提醒接…
- 消息推送及提醒功能构想
- 使用Python制作自动推送微信消息提醒的备忘录功能
- Android luancher消息提醒-ShortcutBadger
- redis 实现消息提醒与历史消息
- rails中使用flash变量启用消息提醒
- Android仿qq实现锁屏消息提醒