Android 来自字符串资源的多语言警报
我有个警报。代码是有效的。我有多个字符串语言文件夹Android 来自字符串资源的多语言警报,android,multilingual,getresource,Android,Multilingual,Getresource,我有个警报。代码是有效的。我有多个字符串语言文件夹res/values/strings.xml&res/values es/strings.xml等。这对于UI很好,但是警报标题、按钮标题和警报消息,我也希望使用其他语言。它一直以默认语言(英语)显示。如果我尝试使用字符串变量&getResources().getString(R.String.name)应用程序失败。医生说。。。我看到其他人也提出了类似的问题,但没有任何回应。有人知道怎么解决这个问题吗?指定区域设置还是什么 public voi
res/values/strings.xml
&res/values es/strings.xml
等。这对于UI很好,但是警报标题、按钮标题和警报消息,我也希望使用其他语言。它一直以默认语言(英语)显示。如果我尝试使用字符串变量&getResources().getString(R.String.name)代码>应用程序失败。医生说。。。我看到其他人也提出了类似的问题,但没有任何回应。有人知道怎么解决这个问题吗?指定区域设置还是什么
public void showSettingsAlert(){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
//String title_settings = getResources().getString(R.string.Settings);
//String title_cancel = getResources().getString(R.string.Cancel);
//String GPS_settings = getResources().getString(R.string.GPS_Settings);
//String GPS_not_enabled = getResources().getString(R.string.GPS_not_enabled);
//String title_settings =getResources().getString(R.string.Settings);
// Setting Dialog Title
alertDialog.setTitle("GPS Settings");
//alertDialog.setTitle(GPS_settings);
// Setting Dialog Message
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
//alertDialog.setMessage(GPS_not_enabled);
// On pressing Settings button
alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
//alertDialog.setPositiveButton(settings, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mContext.startActivity(intent);
}
});
// on pressing cancel button
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
//alertDialog.setNegativeButton(cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
在Android中,资源名称不能包含大写字母。将资源名称更改为使用小写字母,这将解决您的问题