美文网首页
Context作用

Context作用

作者: csp | 来源:发表于2017-03-03 14:26 被阅读16次

Context访问资源用的。
TextView的初始化:
textView = new TextView(MainActivity.this);或者textView = new TextView(R.string.hello_world);直接通过资源id获取资源字符串初始化。
getResources().getText(R.string.hello_world)可以获取到字符串资源,还可以使用getResources()来获取其他的资源,比如图标资源;
ImageView iv = new ImageView(this);
iv.setImageResource(R.mipmap.ic_launcher);

相关文章

网友评论

      本文标题:Context作用

      本文链接:https://www.haomeiwen.com/subject/ywxrgttx.html