作者qweqweqweqwe (啪)
看板AndroidDev
标题Re: [问题] APP多语系不跟着手机预设
时间Sat Jul 20 02:04:57 2013
献丑一下,刚好最近有碰到
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
1F:→ sulf:重开一样是因为还没被系统杀掉吧 07/20 06:15
2F:→ sulf:抱歉如果是写死怎麽开都会是日语 07/20 19:30
3F:推 zxc190:不知道是不是我想要的 但是感谢分享^^ 我来study一下 07/20 23:30
4F:推 zxc190:我想请问的是updateConfiguration 这个有将语系存到 07/20 23:54
5F:→ zxc190:某个档案,等到下次开起的时後使用麻 没有的话可能要用 07/20 23:54
6F:→ zxc190:Pregerence了 07/20 23:55