安卓国际化

    xiaoxiao2021-03-25  69

    首先,第一次写博客,会有很多理解不到位的地方,还请诸位谅解.首先先介绍一下安卓国际化,顾名思义就是安卓的多种语言以及多种语言环境.也就是说把安卓项目中的res 文件夹下新建对应语言的 values就ok了.如果是英语环境就用values-en-rUS ,中文环境就用values-zh-cn.我们还是用一个项目来具体解释一下安卓国际化.先来看一下结果图.

    实现这个功能,首先我们应该想到的是页面布局,把布局先列出.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        xmlns:tools="http://schemas.android.com/tools"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:background="@android:color/darker_gray"

        android:orientation="vertical"

        tools:context=".MainActivity" >

        <RelativeLayout style="@style/h_wrap_content"

            android:layout_marginTop="10dp">

            <TextView

                style="@style/tv_style"

                android:layout_alignParentLeft="true"

                android:layout_marginLeft="10dp"

                android:drawableTop="@drawable/clound"

                android:text="@string/_cloud" />

            <TextView

                style="@style/tv_style"

                android:layout_alignParentRight="true"

                android:layout_marginRight="10dp"

                android:drawableTop="@drawable/bluetooth"

                android:text="@string/_bluetooth" />

        </RelativeLayout>

        <RelativeLayout style="@style/h_wrap_content"

            android:layout_marginTop="10dp">

            <TextView

                style="@style/tv_style"

                android:layout_alignParentLeft="true"

                android:layout_marginLeft="10dp"

                android:drawableTop="@drawable/gesture"

                android:text="@string/_gesture" />

            <TextView

                style="@style/tv_style"

                android:layout_alignParentRight="true"

                android:layout_marginRight="10dp"

                android:drawableTop="@drawable/gps"

                android:text="@string/_gps" />

        </RelativeLayout>

        <RelativeLayout style="@style/h_wrap_content"

            android:layout_marginTop="10dp">

            <TextView

                style="@style/tv_style"

                android:layout_alignParentLeft="true"

                android:layout_marginLeft="10dp"

                android:drawableTop="@drawable/info"

                android:text="@string/_system_info" />

            <TextView

                style="@style/tv_style"

                android:layout_alignParentRight="true"

                android:layout_marginRight="10dp"

                android:drawableTop="@drawable/internet"

                android:text="@string/_internet" />

        </RelativeLayout>

        <RelativeLayout style="@style/h_wrap_content"

            android:layout_marginTop="10dp">

            <TextView

                style="@style/tv_style"

                android:layout_alignParentLeft="true"

                android:layout_marginLeft="10dp"

                android:drawableTop="@drawable/language"

                android:text="@string/_language" />

            <TextView

                style="@style/tv_style"

                android:layout_alignParentRight="true"

                android:layout_marginRight="10dp"

                android:drawableTop="@drawable/notifycation"

                android:text="@string/_set_notifycation" />

        </RelativeLayout>

    </LinearLayout>

    这样大体的布局以及文本的分布就已经列出了.

    然后在String文件中编写相应的string.xml文件

    然后在style.xml文件中编写格式.这个项目就完成了.让我们大体的认识了安卓以及安卓国际化.希望在接下来的学习中可以更加丰富自己的安卓知识.

    转载请注明原文地址: https://ju.6miu.com/read-32342.html

    最新回复(0)