ChangeLanguage.java
package montercodz.blogspot.com; import java.util.Locale; import android.content.Context; import android.content.res.Configuration; import android.util.Log; public class ChangeLanguage { public static String ENGLISH = "en"; public static String FRENCH = "fr"; public static String LANGUAGE = "fr"; public static void changeLanguage(Context context,String language){ Locale localeSetting = new Locale(language); Locale.setDefault(localeSetting); Configuration configSetting = new Configuration(); configSetting.locale = localeSetting; context.getResources().updateConfiguration(configSetting, null); Log.d("Localization.java","Language have been changed!"); } }
MainClass.java
package montercodz.blogspot.com; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainClass extends Activity implements OnClickListener { private Button btnEnglish; private Button btnFrench; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnEnglish = (Button)findViewById(R.id.btnEnglish); btnFrench = (Button)findViewById(R.id.btnFrench); //set Button listener btnEnglish.setOnClickListener(this); btnFrench.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub if(btnEnglish == v){ //set English language start ChangeLanguage.LANGUAGE = ChangeLanguage.ENGLISH; ChangeLanguage.changeLanguage(this,ChangeLanguage.LANGUAGE); Intent i = new Intent(getApplication(),SecodeUserInterface.class); startActivity(i); }else if(btnFrench == v){ //set French language start ChangeLanguage.LANGUAGE = ChangeLanguage.FRENCH; ChangeLanguage.changeLanguage(this,ChangeLanguage.LANGUAGE); Intent i = new Intent(getApplication(),SecodeUserInterface.class); startActivity(i); } } }
SecodeUserInterface.java
package montercodz.blogspot.com; import android.app.Activity; import android.os.Bundle; public class SecodeUserInterface extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); //set language change be fore setContentView this set use in all UI language change ChangeLanguage.changeLanguage(this, ChangeLanguage.LANGUAGE); setContentView(R.layout.second_user_interface); } }
main.xml
second_user_interface.xml
String.xml (for english)
Change Language Example Language description changes depending on language
String.xml (for French)
Changements langage de description de fonction de la langue
to change with other language you need to change your directory name click Here for more language.
AndroidManifest.xml
your directory should look like this bellow picture
this is your buttonDrawable Image
Source code you can download here
Change language Source code download
0 comments:
Post a Comment