首先创建多语言资源,参考 在MainActivity的onCreate()中添加如下代码
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
String languageToLoad = "zh"; Locale locale = new Locale(languageToLoad); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, null);
}
AndroidManifest.xml中:
<application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="locale"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
</application> <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true"/>
每一个Activity中都要加: android:configChanges="locale"。 加 <supports-screens>是为了解决如下问题: http://adrianvintu.com/blogengine/post/Force-Locale-on-Android.aspx
|