在Java的Andr​​oid的onClick按钮语言的变化 [英] Onclick button language change in java android

查看:116
本文介绍了在Java的Andr​​oid的onClick按钮语言的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方式来落实按钮的onclick触发语言的变化。我在正确的文件夹中创建适当的strings.xml(例如RES /值恩/)这里是按钮的我的code:

I'm looking for a way to implement change of language triggered by button onclick. I have created proper strings.xml in proper folders (for example res/values-en/) Here is my code of the button:

Button setEN_bt = (Button) findViewById(R.id.setEN);        
setEN_bt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Locale locale_en = new Locale("en"); 
            Locale.setDefault(locale_en);
            Configuration config_en = new Configuration();
            config_en.locale = locale_en;
            getBaseContext().getResources().updateConfiguration(config_en, getBaseContext().getResources().getDisplayMetrics());
        }
    });

所以我basicly更改区域用的onclick但页面不刷新后(何必呢...... :))。有人能告诉我如何刷新/重载的活动?

So basicly I change the locale with the onclick but the page doesn't refresh afterwards (why should it...:) ). Could somebody tell me how to refresh/reload the activity?

为感谢名单提前帮助。

推荐答案

您可以尝试调用

view.invalidate();

这是您要重绘自己的看法。

on the view that you want redraw itself.

我不知道,如果这将刷新区域设置。如果没有,你可以通过为自己创建一个新的意图重新启动活动:

I'm not sure, if this will reload the Locales. If not, you could restart the Activity by creating a new Intent for itself:

Intent intent = new Intent(this, Activity.class);
startActivity(intent);

干杯

这篇关于在Java的Andr​​oid的onClick按钮语言的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆