Context的作用

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);
    }

 

posted @ 2015-08-07 09:05  Rosanne  阅读(226)  评论(0编辑  收藏  举报