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

来源:互联网 发布:逆战自动开枪脚本源码 编辑:程序博客网 时间:2024/06/05 16:17

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);
0 0
原创粉丝点击