Android 国际化语言设置,简单粗暴。

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_26841579/article/details/80311884

在网上看了一大堆。核心代码就是那几句,但是,还有的细节可能没注意导致 无法改变。

直接贴代码。

 public void setLanguage(int type){
        Resources resources=getResources();//获得res资源对象
        Configuration config=resources.getConfiguration();//获得设置对象
        DisplayMetrics dm=resources.getDisplayMetrics();//获得屏幕参数:主要是分辨率像素等。
        if(type==0){
            config.locale= Locale.SIMPLIFIED_CHINESE;
        }else if(type==1){
            config.locale= Locale.ENGLISH;
        }else if(type==2){
            config.locale= Locale.KOREA;
        }else if(type==3){
            config.locale= Locale.JAPANESE;

        }else{

        }
        resources.updateConfiguration(config,dm);
        startActivity(MainActivity.class);
    }
    public static int language_type=0; //0是 中文,1是英语,2是韩语,3是日语。

代码没什么难的。
注意注意注意
这里有个地方要注意,我就是因为这样的原因导致不能够实现的。

这里写图片描述

看清楚文件夹名字。
不知道为啥,这样生成出来的不能用

后来把vlues 文件名字改了才能用
这里写图片描述

还是要细心啊。马虎不得。

猜你喜欢

转载自blog.csdn.net/qq_26841579/article/details/80311884
今日推荐