Activity extends Context Context extends Object
TextView extends View ImageView extends View
View extends Object Resources extends Object
1)Activity 中 onCreate() 下的部分应用
1-> 访问资源文件 res\string 目录下字符串
protecter void onCreate(Bundle saveInstanceState){ super.onCreate(saveInstanceState); TextView tv = new TextView(this); // tv.setText("Hello Android"); tv.setText(R.string.hello_world); setContentView(tv); system.out.println(getResources().getText(R.string.hello_wrold)); }
textview.setText(Int resID); textview.setText(" ");
activity.getResources(); resources.getText(Int resID);
2 -> 访问资源文件 res\mipmap 目录下图标
protecter void onCreate(Bundle saveInstanceState){ super.onCreate(saveInstanceState); ImageView iv = new ImageView(this); iv.setImageResource(R.mipmap.ic_laucher); setContentView(iv); }
imageview.setImageResource(int resID);
activity.setContentView(View);
时间: 2024-10-11 07:34:56