我们所有的资源都会在R.java中生成id,我们可以通过这个资源id来完成资源的访问,使用情况有两种:Java代码中使用和XML代码中使用:
Java代码中使用:
Java 文字:
txtName.setText(getResources().getText(R.string.name)); 图片: imgIcon.setBackgroundDrawableResource(R.drawable.icon); 颜色: txtName.setTextColor(getResouces().getColor(R.color.red)); 布局: setContentView(R.layout.main); 控件: txtName = (TextView)findViewById(R.id.txt_name) XML代码中使用:代码的使用: androoid:orientaion="vertical"为线性布局的指定方式,组件的排序是水平的(horizontal),垂直的是(vertical).