3-2

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代码中使用:

通过@xxx即可得到,比如这里获取文本和图片:

<TextView android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background = "@drawable/img_back"/>
posted @ 2022-05-27 10:20  清谦  阅读(77)  评论(0编辑  收藏  举报