Android基础之在程序代码中引用资源(color&mipmap&string)

1.设置背景图片,图片来源于drawable;

TextView.setBackgroundDrawable(getResources().getDrawable(R.drawable.search));
TextView..setBackgroundResource(R.drawable.search);

2.设置背景颜色

TextView.setBackgroundColor(getResources().getColor(R.color.bg_red));
TextView..setBackgroundColor(0xFFFF0000);

2.转换字符串为int(颜色);

TextView.deleteFilghtBg.setBackgroundColor(Color.parseColor("#F5F5DC"));

3.使用String资源

this.getResources().getString(R.string.setIP);

你可能感兴趣的:(Android基础之在程序代码中引用资源(color&mipmap&string))