我有一个应用程序,您可以在其中更改设置中的区域设置(目的是在应用程序内部具有与系统区域设置不同的区域设置),并且我希望能够设置地图的语言同样。我只能找到像“设置手机的系统语言”这样的答案,这不是我想要的。有没有办法以编程方式或从xml设置地图的语言?
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"/>
答案 0 :(得分:0)
data-attr2