3

I know that to support different language I have to add the res/values-el for example.

And I can't change by that all the buttons, TextViews etc.

But, if my app uses for example an AlertDialog, can I change the language of the title etc?

...
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
alt_bld.setMessage("Do you want to navigate to the saved position?")
.setCancelable(false)
.setPositiveButton("Navigate",
alert.setTitle("Navigation");    
...

Ok, if anyone wants to do that from a service he must use :

mContext.getString(R.string.Title)  //where mContext is the Context

instead of

getResources().getString(R.string.Title)
4

1 回答 1

1

是的,您只需要从strings.xml. 不要在代码中硬编码字符串。文档

例如:

alert.setTitle(getResources().getString(R.string.navigation));   

res/values/strings.xml你定义:

<string name="navigation">Navigation</string>

res/values-pl/strings.xml(例如波兰语)中:

<string name="navigation">Nawigacja</string>
于 2013-06-05T18:01:24.583 回答