在android studio里新建项目
-
工程项目结构解析:
res中所有资源都会在R.java中生成对应的资源id,可以用资源id来获得对应的资源
-
如何使用各种资源
1、java代码 中使用:
//文字:
txtName.setText(getResources().getText(R.string.name));
//图片:
imagIcon.setBackgroundDrawableResource(R.drawable.icon);
//颜色:
txtName.setTextColor(getResources().getColor(R.color.red));
//布局:
setContentView(R.layout.main);
//控件:
txtName=(TextView)findViewById(R.id.txt_name);
2、XML代码中使用
通过@xxx得到,下面展示获取文本与图片实例:
<!--获取文本、图片-->
<TextView android:text= "@string/hello_word"
android:layout_width= "wrap_content"
android:layer_height= "wrap_content"
android:background= "@drawable/img_back" />