set android app lanuage programatically

问题:

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

转载于:https://www.cnblogs.com/howarddeng/p/5448231.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值