Android之获取string.xml文件里面的方法

获取string.xml文件里面的方法

在此做个笔记:

1.在AndroidManifest.xml与layout等xml文件里:

android:text="@string/resource_name" 

  

2.在activity里:

方法一:this.getString(R.string.resource_name);  

方法二:getResources().getString(R.string.resource_name); 

方法三:

 View view = getView();

final Context context = getView().getContext();

context.getResources().getString(R.string.resource_name);

或者getString(int id,Object ...obj);

R.string.resource_name 是int类型的

3.在其他java文件(必须有Context或pplication)

方法一: context.getString(R.string.resource_name); 

方法二: application.getString(R.string.resource_name);  

posted @ 2016-09-08 18:38  CXQDCXQD  阅读(6545)  评论(0编辑  收藏  举报