Android app的国际化
2016-06-27 00:19
435 查看
如何将anroid app应用国际化?这个其实只需要我们在res/目录下存放不同国家的资源文件,系统就会根据设置的语言不同找到相应res文件夹下的国家资源文件!下面我来写一个简单的实例来演示如何将一个android app实例化。
app资源文件布局
如上图所示,我们需要创建需要订制化的那些国家的相关的资源文件夹,drawable文件夹里面现在存放的是文件名相同的国家国旗logo.bmp, values文件夹里面存放的是不同国家语言的文字信息等的string.xml文件。其实文件名都是相同的,不同的是文件夹名,一个国家对应着一个资源文件夹!
values文件夹里面的不同string.xml文件
app的xml文件
<TextView
android:layout_gravity="center_horizontal"
style="@style/textStyle"
android:text="@string/hello_world" />
<TextView
android:layout_gravity="center_horizontal"
style="@style/textStyle_content"
android:text="@string/hello_world" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo">
</ImageView>
app的style.xml文件
<style name="textStyle">
<item name="android:textColor">#ff0000</item>
<item name="android:textSize">15sp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
</style>
<style name="textStyle_content" parent="textStyle">
<item name="android:textColor">#0ff000</item>
</style>
演示效果
app资源文件布局
如上图所示,我们需要创建需要订制化的那些国家的相关的资源文件夹,drawable文件夹里面现在存放的是文件名相同的国家国旗logo.bmp, values文件夹里面存放的是不同国家语言的文字信息等的string.xml文件。其实文件名都是相同的,不同的是文件夹名,一个国家对应着一个资源文件夹!
values文件夹里面的不同string.xml文件
app的xml文件
<TextView
android:layout_gravity="center_horizontal"
style="@style/textStyle"
android:text="@string/hello_world" />
<TextView
android:layout_gravity="center_horizontal"
style="@style/textStyle_content"
android:text="@string/hello_world" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo">
</ImageView>
app的style.xml文件
<style name="textStyle">
<item name="android:textColor">#ff0000</item>
<item name="android:textSize">15sp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
</style>
<style name="textStyle_content" parent="textStyle">
<item name="android:textColor">#0ff000</item>
</style>
演示效果
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories