获取,MyView 就是定义在**** 里的 名字,获取里面属性用 名字_ 属性 连接起来就可以.TypedArray 通常最后调用 .recycle() 方法,为了保持以后使用该属性一致性!
[java] view plain copy
-
public MyView(Context context,AttributeSet attrs)
-
{
-
super(context,attrs);
-
mPaint = new Paint();
-
TypedArray a = context.obtainStyledAttributes(attrs,
-
R.styleable.MyView);
-
int textColor = a.getColor(R.styleable.MyView_textColor,
-
0XFFFFFFFF);
-
float textSize = a.getDimension(R.styleable.MyView_textSize, 36);
-
mPaint.setTextSize(textSize);
-
mPaint.setColor(textColor);
-
a.recycle();
-
}
MyView.java 全部代码如下:
[java] view plain copy
-
package com.android.tutor;
-
import android.content.Context;
-
import android.content.res.TypedArray;
-
import android.graphics.Canvas;
-
import android.graphics.Color;
-
import android.graphics.Paint;
-
import android.graphics.Rect;
-
import android.graphics.Paint.Style;
-
import android.util.AttributeSet;
-
import android.view.View;
-
public class MyView extends View {
-
private Paint mPaint;
-
private Context mContext;
-
private static final String mString = “Welcome to Mr Wei’s blog”;
-
public MyView(Context context) {
-
super(context);
-
mPaint = new Paint();
-
}
-
public MyView(Context context,AttributeSet attrs)
-
{
-
super(context,attrs);
-
mPaint = new Paint();
-
TypedArray a = context.obtainStyledAttributes(attrs,
-
R.styleable.MyView);
-
int textColor = a.getColor(R.styleable.MyView_textColor,
-
0XFFFFFFFF);
-
float textSize = a.getDimension(R.styleable.MyView_textSize, 36);
-
mPaint.setTextSize(textSize);
-
mPaint.setColor(textColor);
-
a.recycle();
-
}
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
最后看一下《Android框架体系架构(高级UI+FrameWork源码)》学习需要的所有知识点的思维导图。在刚刚那份学习笔记里包含了下面知识点所有内容!文章里已经展示了部分!如果你正愁这块不知道如何学习或者想提升学习这块知识的学习效率,那么这份学习笔记绝对是你的秘密武器!
学习需要的所有知识点的思维导图。在刚刚那份学习笔记里包含了下面知识点所有内容!文章里已经展示了部分!如果你正愁这块不知道如何学习或者想提升学习这块知识的学习效率,那么这份学习笔记绝对是你的秘密武器!
[外链图片转存中…(img-GC92ug2C-1710575020531)]