开发者

change the language in android application

I'm writing an application were it require开发者_StackOverflow中文版s to change the language of the application as and when the user requires. The data in different language is stored in the data base, from which the data is fetched and the UI is updated. I'm want to what should be done if device does not support the particular language font. Any help will be much appreciated.Thanks in advance. _/|_


I don't know more about this but ...

for example if you want your application to support both English and French strings (in addition to the default strings), you can simply create two additional resource directories called /res/values-en (for the English strings.xml) and /res/values-fr (for the French strings.xml).

Within the strings.xml files, the resource names are the same.

For example, the /res/values-en/strings.xml file could look like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello in English!</string>
</resources>

Whereas, the /res/values-fr/strings.xml file would look like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Bonjour en Français!</string>
</resources>

A default layout file in the /res/layout directory that displays the string refers to the string by the variable name @string/hello, without regard to which language or directory the string resource is in.

The Android operating system determines which version of the string (French, English, or default) to load at runtime.A layout with a TextView control to display the string might look like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello" >
</LinearLayout>

The string is accessed programmatically in the normal way:

String str = getString(R.string.hello);

It’s as easy as that.

More you will found Here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜