如何从android的string.xml中读取值?
我写了这行:
String Mess = R.string.mess_1 ;  获取string值,而不是返回string,它是给我的整数types的ID。 我怎样才能得到它的string值? 我提到了string.xml文件中的string值。 
尝试这个
 String mess = getResources().getString(R.string.mess_1); 
UPDATE
 String string = getString(R.string.hello); 
 您可以使用getString(int)或getText(int)来检索string。  getText(int)将保留应用于该string的getText(int)文本样式。 
参考: https : //developer.android.com/guide/topics/resources/string-resource.html
在活动中:
 this.getString(R.string.resource_name) 
如果不是在活动中,但可以访问上下文:
 context.getString(R.string.resource_name) application.getString(R.string.resource_name) 
我正在使用这个:
 String URL = Resources.getSystem().getString(R.string.mess_1); 
顺便说一下,也可以在strings.xml中创buildstring数组,如下所示:
 <string-array name="tabs_names"> <item>My Tab 1</item> <item>My Tab 2</item> </string-array> 
然后从你的活动,你可以得到这样的参考:
 String[] tab_names = getResources().getStringArray(R.array.tab_names); String tabname1=tab_names[0];//"My Tab 1" 
仅供将来参考。
在string资源文档中说:
您可以使用getString(int)或getText(int)来检索string。 getText(int)将保留应用于该string的任何富文本样式。
解决scheme1
 Context context; String mess = context.getString(R.string.mess_1) 
解决scheme2
 String mess = getString(R.string.mess_1) 
 在Android中使用getResources()之前,您必须引用上下文名称。 
 String user=getApplicationContext().getResources().getString(R.string.muser); 
要么
 Context mcontext=getApplicationContext(); String user=mcontext.getResources().getString(R.string.muser); 
在片段中,您可以使用
 getActivity().getString(R.id.whatever); 
如果你想添加string值到一个button,例如,简单的使用
 android:text="@string/NameOfTheString" 
strings.xml中定义的文本如下所示:
  <string name="NameOfTheString">Test string</string> 
你可以使用这个代码:
的getText(R.string.mess_1);
基本上,您需要将资源ID作为parameter passing给getText()方法。
**
我希望这个代码是有益的
**
 String user = getResources().getString(R.string.muser); 
当你写R.你指的是由Eclipse创build的R.java类,使用getResources()。getString()并传递你想要从getString()方法内读取的资源的ID …
如果你在一个活动,你可以使用
。getResources()的getString(R.string.whatever_string_youWant);
如果你不在一个活动使用这个:
getApplicationContext.getResource()。的getString(R.String.Whatever_String_you_want)