THIS CLASS TEACHES YOU TO
YOU SHOULD ALSO READ
It’s always a good practice to extract UI strings from your app code and keep them in an external file. Android makes this easy with a resources directory in each Android project.
If you created your project using the Android SDK Tools (readCreating an Android Project), the tools create a res/
directory in the top level of the project. Within this res/
directory are subdirectories for various resource types. There are also a few default files such as res/values/strings.xml
, which holds your string values.
Create Locale Directories and String Files
To add support for more languages, create additional values
directories inside res/
that include a hyphen and the ISO country code at the end of the directory name. For example, values-es/
is the directory containing simple resourcess for the Locales with the language code "es". Android loads the appropriate resources according to the locale settings of the device at run time.
Once you’ve decided on the languages you will support, create the resource subdirectories and string resource files. For example:
MyProject/ res/ values/ strings.xml values-es/ strings.xml values-fr/ strings.xml
Add the string values for each locale into the appropriate file.
At runtime, the Android system uses the appropriate set of string resources based on the locale currently set for the user's device.
For example, the following are some different string resource files for different languages.
English (default locale), /values/strings.xml
:
<?xml version="1.0" encoding="utf-8"?><resources><stringname="title">My Application</string><stringname="hello_world">Hello World!</string></resources>
Spanish, /values-es/strings.xml
:
<?xml version="1.0" encoding="utf-8"?><resources><stringname="title">Mi Aplicación</string><stringname="hello_world">Hola Mundo!</string></resources>
French, /values-fr/strings.xml
:
<?xml version="1.0" encoding="utf-8"?><resources><stringname="title">Mon Application</string><stringname="hello_world">Bonjour le monde !</string></resources>
Note: You can use the locale qualifier (or any configuration qualifer) on any resource type, such as if you want to provide localized versions of your bitmap drawable. For more information, see Localization.
Use the String Resources
You can reference your string resources in your source code and other XML files using the resource name defined by the <string>
element's name
attribute.
In your source code, you can refer to a string resource with the syntax R.string.<string_name>
. There are a variety of methods that accept a string resource this way.
For example:
// Get a string resource from your app'sResources
String hello =getResources()
.getString(R.string.hello_world);// Or supply a string resource to a method that requires a stringTextView textView =newTextView(this); textView.setText(R.string.hello_world);
In other XML files, you can refer to a string resource with the syntax @string/<string_name>
whenever the XML attribute accepts a string value.
For example:
<TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/hello_world"/>
相关推荐
android机型适配讲解,从概念,设计,适配方案详细讲解android机型适配
提供了android 屏幕适配方案,使用教程 https://blog.csdn.net/qq_17827919/article/details/81027491。
Android屏幕适配Android屏幕适配Android屏幕适配Android屏幕适配Android屏幕适配
现在android手机的屏幕样式一大推,如果要让软件都能匹配多种屏幕,那确实是一件很蛋疼的事,那话不多说怎么才能让软件匹配多种屏幕,答案就是权重也就是android:layout_weight。
这是一篇关于Android屏幕适配的介绍
直接输入UI的安卓效果图px值在layout.xml文件里面,就会自动的适配所以android 的机型,解决了碎片化。
适配android各种机型demo,不需要在写多个dimnes,简单易懂
Android开发之屏幕适配values资源,直接复制到res文件夹下,引用即可实现屏幕适配
android屏幕适配方案,做到了全适配
Android屏幕适配生成文件
Android11 适配,拍照问题。兼容Android11 targetSDk 31。有拍照功能和从相册选择图片,获取图片路径,保存图片。关联文章https://blog.csdn.net/u013778491/article/details/125638960
A low-cost Android screen adaptation solution (今日头条屏幕适配方案终极版,一个极低成本的 Android 屏幕适配方案)
android屏幕适配方法
针对Android屏幕适配所整合的几种常用方案
相关博客:【android学习开源项目之AndroidAutoSize】AndroidAutoSize和DialogFragment的适配 https://blog.csdn.net/ljb568838953/article/details/103906449; 本demo的知识点:1.AndroidAutoSize 的使用(今日...
android屏幕适配的demo。
介绍Android手机适配,大、中、小屏手机的处理办法以及图片如何处理。
Android屏幕适配:dimens自动生成工具以及使用方法,亲测好用,需要通过多套dimens做android屏幕适配的同学可以下载了,里面包括使用方法,方便易懂
做屏幕适配px单位的工具类,具体用法可以参照我的博客《android适配解决方案》
Android国际化的例子有很多,但是都是老的,有的在Android7.0以上是没办法实现多语言。这个例子的需求是这样的:App每次启动都去读取手机本地设置的语音环境,如果是中文,不管简体繁体,都显示中文,其他的语言则...