我试图通过变量(语言)来改变文本,但即使语言变量的值是“阿尔巴尼亚”,按钮的文本也没有改变!按钮文本没有改变
P.S变量值从另一个活动传递。
String language="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_level_activity_layout);
btnBegginer=(Button)findViewById(R.id.btnBegginer);
btnMedium=(Button)findViewById(R.id.btnMedium);
btnHard=(Button)findViewById(R.id.btnHard);
Intent objIntent=getIntent();
language=objIntent.getStringExtra("language");
//Toast.makeText(getApplicationContext(),language,Toast.LENGTH_LONG).show();
if (language=="albanian")
{
btnBegginer.setText("FILLESTAR");
btnMedium.setText("MESATARE");
btnHard.setText("VESHTIRE");
}
else
{
btnBegginer.setText("BEGGINER");
btnMedium.setText("MEDIUM");
btnHard.setText("HARD");
}
你不应该硬编码字符串,尤其是如果它受到定位。您应该将字符串放入'string.xml'文件中,并根据系统设置提供替代文件。查看[this](https://developer.android.com/guide/topics/resources/localization.html)了解更多详情 – Sunshinator