您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
80_程序的国际化
发布时间:2021-03-23 21:36:35编辑:雪饮阅读()
今天呢,给大家带来的是程序的国际化,所谓国际化呢就是多语言。那么所谓多语言呢,就是让程序支持不同的语言环境来自适应。刚开始接触呢,感觉应该挺高大上的,其实呢,还是得靠我们来实现。
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/flag"
/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
这里values-en/strings.xml:
这里values-zh/strings.xml:
那么对于图片资源也是同样的,这里适配了语言环境不匹配时候的国旗图片
<string name="hello">Hello World, DemoActivity!</string>
<string name="app_name">I18N</string>
</resources>
<resources>
<string name="hello">en Hello World, DemoActivity!</string>
<string name="app_name">en I18N</string>
</resources>
<resources>
<string name="hello">你好世界</string>
<string name="app_name">国际化</string>
</resources>
关键字词:android,国际化,语言
上一篇:79_android下的手势识别
下一篇:81_程序的屏幕适配