android多语言切换

来源:互联网 发布:access数据库编辑器 编辑:程序博客网 时间:2024/06/01 09:26
string.xml英文<?xml version="1.0" encoding="utf-8"?><resources>    <string name="TextView1">ONE</string>    <string name="TextView2">TWO</string></resources>string.xml中文<?xml version="1.0" encoding="utf-8"?><resources>    <string name="TextView1">第一个</string>    <string name="TextView2">第二个</string></resources></span>


MainActivity.xml

package com.sec.lifeactivity;import java.util.Locale;import android.os.Bundle;import android.widget.TextView;import android.app.Activity;import android.content.res.Configuration;public class MainActivity extends Activity {    TextView textView1;    TextView textView2;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);// 总是先调用上级类方法        setContentView(R.layout.activity_main);        //默认英文        textView2 = (TextView) findViewById(R.id.textView2);        textView2.setText(R.string.TextView2);        Configuration configuration = getResources().getConfiguration();// 获取系统的配置        configuration.locale = Locale.CHINA;        getResources().updateConfiguration(configuration,                getResources().getDisplayMetrics());        textView1 = (TextView) findViewById(R.id.textView1);        textView1.setText(R.string.TextView1);          }}


0 0
原创粉丝点击