1. 程式人生 > >Android 國際化語言設定,簡單粗暴。

Android 國際化語言設定,簡單粗暴。

在網上看了一大堆。核心程式碼就是那幾句,但是,還有的細節可能沒注意導致 無法改變。

直接貼程式碼。

 public void setLanguage(int type){
        Resources resources=getResources();//獲得res資源物件
        Configuration config=resources.getConfiguration();//獲得設定物件
        DisplayMetrics dm=resources.getDisplayMetrics();//獲得螢幕引數:主要是解析度畫素等。
        if(type
=
=0){ config.locale= Locale.SIMPLIFIED_CHINESE; }else if(type==1){ config.locale= Locale.ENGLISH; }else if(type==2){ config.locale= Locale.KOREA; }else if(type==3){ config.locale= Locale.JAPANESE; }else{ } resources.updateConfiguration(config,dm); startActivity(MainActivity.class
); }
    public static int language_type=0; //0是 中文,1是英語,2是韓語,3是日語。

程式碼沒什麼難的。
注意注意注意
這裡有個地方要注意,我就是因為這樣的原因導致不能夠實現的。

這裡寫圖片描述

看清楚資料夾名字。
不知道為啥,這樣生成出來的不能用

後來把vlues 檔名字改了才能用
這裡寫圖片描述

還是要細心啊。馬虎不得。