1
我有一个应用程序,您可以从设置中更改区域设置(目的是能够在应用程序内部具有与系统区域设置不同的区域设置),而我希望能够设置地图的语言。我只能找到像“设置您的手机的系统语言”,这不是我正在寻找的答案。有没有一种方法来设置地图的语言编程或从XML?如何以编程方式在android google maps v2中更改语言
public class LocalizedActivity extends FragmentActivity {
private GoogleMap map;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// you need to call this ASAP:
setLocaleResources("iw");
// after this most parts of the UI are localized, but not the map
setContentView(R.layout.main);
android.support.v4.app.FragmentManager sfm = getSupportFragmentManager();
final Fragment f = sfm.findFragmentById(R.id.map);
final SupportMapFragment mf = (SupportMapFragment) f;
map = mf.getMap();
}
static void setLocaleResources(final String languageCode) {
final Context context = RedAlert.getContext();
Resources res = context.getResources();
// Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale(languageCode);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
conf.setLayoutDirection(conf.locale);
}
res.updateConfiguration(conf, dm);
}
的main.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
一个非常糟糕的主意。 Google建议您不要更改语言,而是使用用户选择的语言。 – Martin 2014-10-07 22:04:58
@Martin,其实这是一个非常好的主意。 “您可以从设置中更改区域设置”,但不必更改默认(系统)语言。为什么会这样做有几个原因。例如,我的手机的默认语言是en_US,但是这个应用程序在希伯来语中是“更好”的,因为显示的一些实时数据没有被翻译成英语,并且由于ltr和rtl文本方向如果应用程序是英文的,那么在句子中混杂起来很难阅读,但是我不想强迫希伯来语对任何人。 – Gavriel 2014-10-07 22:28:50
由于地图由另一个进程渲染,如果您有控制其语言的手段,我会感到很惊讶。 – CommonsWare 2014-10-07 23:52:09