How to set different locales in android
- create new folder with values in resources folder in project with extension your language code
For example:
My language is Czech (cs)
I have to create the folder values-cs in res folder
Into every values folder put strings.xml file
Translate every string from values folder into your locale.
If user selected your locale in device settings, application selects a string from the correct (proper) folder.
For example:
My language is Czech (cs)
I have to create the folder values-cs in res folder
// for locale English is default
/MyProject/res/values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">App English default</string>
<string name="action_settings">Settings English default</string>
<string name="hello_world">Hello world</string>
</resources>
// for locale Czech (cs)
/MyProject/res/values-cs
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Aplikace česky cs</string>
<string name="action_settings">Nastavení česky</string>
<string name="hello_world">Ahoj světe!</string>
</resources>
// for locale English US (r is region)
/MyProject/res/values-en-rUS
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">App English Us locale</string>
<string name="action_settings">Settings English Us locale</string>
<string name="hello_world">Hello world from USA :)</string>
</resources>
Into every values folder put strings.xml file
Translate every string from values folder into your locale.
If user selected your locale in device settings, application selects a string from the correct (proper) folder.
396LW NO topic_id
AD
Další témata ....(Topics)
AlertDialog like MessageBox by WinApi:
If error: Unable to add window -- token null is not for an application
try change get Context.
If error: Unable to add window -- token null is not for an application
try change get Context.
// you can put this text into some function body or case in switch statement
new AlertDialog.Builder(this)
.setMessage("Hello boys!!!")
.setPositiveButton("OK", null)
.show();
Context context = getApplicationContext();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Select font size");
final CharSequence[] chsSize= { "Small", "Medium", "Large"};
builder.setSingleChoiceItems(chsSize, 0 /*sel.item*/,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(context, "Hello from dialog!!!", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
ImputStream is = this.getResources().openRawResource(R.drawable.colors);
Bitmap mBitmap2 = BitmapFactory.decodeStream(is);
int w = mBitmap2.getWidth();
int h = mBitmap2.getHeight();
// int x , y have to be smaller as w , h
int _color = mBitmap2.getPixel(x, y);
Integer, Float, String, List passed as reference in JAVA example source code:
// List passed as reference JAVA
List<Integer>list = new ArrayList<Integer>();
public void fc (List<Integer>listRef){
listRef.add(7);
listRef.add(5);
}
fc(list); // 7, 5
// String passed as reference JAVA
public void mutate(AtomicReference<Object> ref) { ref.set("Goodbye"); }
AtomicReference<Object> ref = new AtomicReference<Object>("Hello");
mutate(ref);
System.out.println(ref.get()); //Goodbye!
String s = (String) ref.get();
// Integer passed as reference JAVA
private static void mutate(AtomicReference<Object> ref) { ref.set(7); }
//public static void main(String[] arg) {
AtomicReference<Object> ref = new AtomicReference<Object>(5);
mutate(ref);
System.out.println(ref.get()); // 7
int n = (Integer) ref.get();
// Float passed as reference JAVA
private static void mutate(AtomicReference<Object> ref) { ref.set(14.8f); }
//public static void main(String[] arg) {
AtomicReference<Object> ref = new AtomicReference<Object>(12.1f);
mutate(ref);
float f = (Float) ref.get();
System.out.println(f); //14.8
If You create new xml file with prefix _ , for example _style.xml and You to clean project (Project->Clean), than package in folder project\gen will deleted with R.java class and new R.java not be created.
For to solving this problem You have to rename file without prefix _ as style.xml or name what You need and rebuild project.
If some ID cannot be resolved or is not a field get error occurence
You have to delete import android.R; in Activity.class if was inserted,
when this error is displayed.
For to solving this problem You have to rename file without prefix _ as style.xml or name what You need and rebuild project.
If some ID cannot be resolved or is not a field get error occurence
You have to delete import android.R; in Activity.class if was inserted,
when this error is displayed.
Editace: 2014-02-12 19:52:37
Počet článků v kategorii: 396
Url:how-to-set-different-locales-in-android