AndroidStudio中gettext在点击后不能更新的问题。
创始人
2024-08-20 22:00:28
0

在Android Studio中更新gettext的过程中,我们需要设置标志来强制更新。为此,可以将以下代码添加到onCreate方法:

Button myButton = findViewById(R.id.myButton);
myButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // Force gettext update
        Locale locale = getResources().getConfiguration().locale;
        Locale.setDefault(locale);
        Resources res = getApplicationContext().getResources();
        Configuration config = new Configuration(res.getConfiguration());
        if (Build.VERSION.SDK_INT >= 17) {
            config.setLocale(locale);
            context = createConfigurationContext(config);
        } else {
            config.locale = locale;
            res.updateConfiguration(config, res.getDisplayMetrics());
        }
        
        // Update gettext value
        String myString = gettext(R.string.my_string);
        TextView myTextView = findViewById(R.id.myTextView);
        myTextView.setText(myString);
    }
});

这段代码会在用户单击myButton按钮时强制更新gettext。同时,它还会从R.string.my_string资源中获取gettext字符串,并将其设置为myTextView的文本。最终结果是,当用户在应用程序中使用gettext时,它将更新为最新的本地化值。

相关内容

热门资讯

透视app!aapoker辅助... 透视app!aapoker辅助器怎么用(透视)辅助插件工具(好像有挂)1、完成aapoker辅助器怎...
透视插件!aa poker辅助... 透视插件!aa poker辅助(透视)ai插件(好像真的有挂);1、下载好aa poker辅助辅助软...
透视总结!aapoker ai... 透视总结!aapoker ai插件(透视)发牌逻辑(切实有挂)1、首先打开aapoker ai插件最...
透视科技!aapoker俱乐部... 透视科技!aapoker俱乐部靠谱吗(透视)真的假的(总是存在有挂);1、操作简单,无需注册,只需要...
透视透视!aapoker透视插... 透视透视!aapoker透视插件(透视)透视脚本入口(竟然是真的有挂)aapoker透视插件辅助器中...
透视实锤!aapoker ai... 透视实锤!aapoker ai插件(透视)透视脚本下载(确实有挂)1、不需要AI权限,帮助你快速的进...
透视游戏!aapoker辅助怎... 透视游戏!aapoker辅助怎么用(透视)辅助(切实是真的有挂);1、这是跨平台的aapoker辅助...
透视透视!aapoker怎么设... 透视透视!aapoker怎么设置提高好牌几率(透视)脚本(一直存在有挂)一、aapoker怎么设置提...
透视中牌率!aapoker脚本... 透视中牌率!aapoker脚本怎么用(透视)插件下载(本来存在有挂);1、进入游戏-大厅左侧-新手福...
透视有挂!aapoker怎么设... 透视有挂!aapoker怎么设置提高好牌几率(透视)真的假的(一直真的是有挂);1、起透看视 aap...