英語とギリシャ語の多言語アプリを作ろうとしています。私が欲しいのは、最初の画面に言語を選択する2つのボタンがあり、他のすべてのアプリがその言語でbveすることだけです。私は2つのボタンと段落で簡単なテストプロジェクトを作成しました。英語のボタンを押すとテキストは英語になり、ギリシャ語のボタンを押すとテキストはギリシャ語になります。私のコード
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page2);
Button english = (Button) findViewById(R.id.english);
english.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Locale locale = new Locale("en_UK");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getApplicationContext().getResources().updateConfiguration(config, null);
Intent intent = new Intent(v.getContext(), MainActivity.class);
startActivityForResult(intent, 0);
}
});
Button greek = (Button) findViewById(R.id.greek);
greek.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Locale locale = new Locale("el_GR");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getApplicationContext().getResources().updateConfiguration(config, null);
Intent intent = new Intent(v.getContext(), MainActivity.class);
startActivityForResult(intent, 0);
}
});
}
英語の段落を含むstrings.xmlは元のres/valuesフォルダーにあり、ギリシャ語を含むstrings.xmlはres/values-elにあります
テスト アプリの 3 つのスクリーンショットを次に示します。いくつかのスクリーンショットを次に示します。
文字以外のものがあるのはギリシャ語の段落です