首页 > 移动平台 > 详细

set android app lanuage programatically

时间:2016-04-30 10:06:54      阅读:258      评论:0      收藏:0      [点我收藏+]
问题:

I am developing a comic app.I have three radio buttons which are english,french and spanish respectively. And when the user clicks on any one of them the strings.xml from values-es,values-fr and values-en should change the string of the required references but and i click on the radio buttons it does not change the references are still in engish and do not change to french or spanish

 



答案:
public class AndroidLocalize extends Activity { Spinner spinnerctrl; Button btn; Locale myLocale; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); spinnerctrl = (Spinner) findViewById(R.id.spinner1); spinnerctrl.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { if (pos == 1) { Toast.makeText(parent.getContext(), "You have selected Es", Toast.LENGTH_SHORT) .show(); setLocale("ta"); } else if (pos == 2) { Toast.makeText(parent.getContext(), "You have selected Fr", Toast.LENGTH_SHORT) .show(); setLocale("hi"); } else if (pos == 3) { Toast.makeText(parent.getContext(), "You have selected En", Toast.LENGTH_SHORT) .show(); setLocale("en"); } } public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); } public void setLocale(String lang) { myLocale = new Locale(lang); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale; res.updateConfiguration(conf, dm); Intent refresh = new Intent(this, AndroidLocalize.class); startActivity(refresh); } }


转自:stack overflow

set android app lanuage programatically

原文:http://www.cnblogs.com/howarddeng/p/5448231.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!