context用于访问全局资源
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = new TextView(this); tv.setText(R.string.hello_world); setContentView(tv); }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView iv = new ImageView(this); iv.setImageResource(R.mipmap.ic_launcher); setContentView(iv); }
时间: 2024-11-03 22:36:10