小编Tom*_*aro的帖子

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

我正在尝试使用颜色元素,getresources.getColor(resource id)但 android 告诉我它已被弃用 use 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 …
Run Code Online (Sandbox Code Playgroud)

android android-theme android-color

-1
推荐指数
1
解决办法
4963
查看次数

标签 统计

android ×1

android-color ×1

android-theme ×1