java getcolor_如何使用新版本的getresources() . getColor?

我试图使用 getresources.getColor(resource id) 获取一个颜色元素但是android告诉我它已被弃用 getresources.getColor(resource id, theme) .

我如何告诉它使用什么主题?我试过 R.style.AppTheme 但是我得到一个错误,因为这是一个int值

public class TodoListItemView extends AppCompatTextView {

public TodoListItemView(Context context, AttributeSet attributeSet, int ds) {

super(context, attributeSet, ds);

init();

}

public TodoListItemView(Context context) {

super(context);

init();

}

public TodoListItemView(Context context, AttributeSet attributeSet) {

super(context, attributeSet);

init();

}

private Paint marginPaint;

private Paint linePaint;

private int paperColor;

private float margin;

private void init() {

Resources myResources = getResources();

marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

marginPaint.setColor(getResources().getColor(R.color.notepad_margin));

linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);

linePaint.setColor(myResources.getColor(R.color.notepad_lines));

paperColor = myResources.getColor(R.color.notepad_paper);

margin = myResources.getDimension(R.dimen.notepad_margin);

}

@Override

public void onDraw(Canvas canvas) {

canvas.drawColor(paperColor);

canvas.drawLine(0, 0, getMeasuredHeight(), 0, linePaint);

canvas.drawLine(0, getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight(), linePaint);

canvas.drawLine(margin, 0, margin, getMeasuredHeight(), marginPaint);

canvas.save();

canvas.translate(margin, 0);

super.onDraw(canvas);

canvas.restore();

}

}

任何帮助是极大的赞赏 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值