zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    激光打印机基于主机驱动程序、基于 PCL 驱动程序和 PostScript 驱动程序有何区别?
    转贴:打印机语言PostScript和PCL的比较
    编译器相关配置简介
    Graphics View的体系结构
    解决重装Qt后不能编译Examples的问题
    有符号数和无符号数的区别
    51单片机的外设
    AT89S52单片机P3口解惑
    双向端口设计
    AT89s52单片机的掉电测试
  • 原文地址:https://www.cnblogs.com/howarddeng/p/5448231.html
Copyright © 2011-2022 走看看