android 應用程序實現語言切換

發表于:2011-06-24來源:未知作者:娃娃點擊數: 標簽:Android
首先創建多語言資源,參考在MainActivity的onCreate()中添加如下代碼 public void onCreate(Bundle savedInstanceState) {

 

首先創建多語言資源,參考

在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

 

 

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97