看板 AndroidDev 關於我們 聯絡資訊
獻醜一下,剛好最近有碰到 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PackageManager pm = this.getPackageManager(); try { Resources r = pm.getResourcesForApplication( pm.getApplicationInfo("com.example.changelocale", 0)); Log.e("QQQQ", r.getString(R.string.hello_world)); r.getConfiguration().locale = new Locale("ja"); r.updateConfiguration(r.getConfiguration(), null); Log.e("QQQQ", r.getString(R.string.hello_world)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } 剛簡單寫一個來試試,在values 跟values-ja 裡面都放 hello_world 字串測試 重開APP後還是可以保留上次的設定,應該是因為這個設到packageManager裡面去了 相對的也可以只設某個 activity .. 之類的 不知道是否是你需要的 ※ 引述《zxc190 (卡卡)》之銘言: : 請問一下 : Locale locale = new Locale("ja"); : Locale.setDefault(locale); : Configuration config = new Configuration(); : config.locale = locale; : Language.this.getResources().updateConfiguration(config, null); : 這段code是可以讓APP語系設為日文 : 但是關掉重開的時候就會讓APP變為手機預設語系 : 請問是要用Preference存好變數麻 : 還是有其他寫法?? 謝謝各位了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.165.78.98
sulf:重開一樣是因為還沒被系統殺掉吧 07/20 06:15
sulf:抱歉如果是寫死怎麼開都會是日語 07/20 19:30
zxc190:不知道是不是我想要的 但是感謝分享^^ 我來study一下 07/20 23:30
zxc190:我想請問的是updateConfiguration 這個有將語系存到 07/20 23:54
zxc190:某個檔案,等到下次開起的時後使用麻 沒有的話可能要用 07/20 23:54
zxc190:Pregerence了 07/20 23:55