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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM