Language Specific layout for android

后端 未结 3 1095
独厮守ぢ
独厮守ぢ 2020-12-31 12:15

I know that we can display multiple languages support for our android application with different values folder example values-en , values-ar.

My question is can we

相关标签:
3条回答
  • 2020-12-31 12:21

    The layout direction of your application. ldrtl means "layout-direction-right-to-left". ldltr means "layout-direction-left-to-right" and is the default implicit value.

    This can apply to any resource such as layouts, drawables, or values.

    For example, if you want to provide some specific layout for the Arabic language and some generic layout for any other "right-to-left" language (like Persian or Hebrew) then you would have:

    res/
    layout/   
        main.xml  (Default layout)
    layout-ar/  
        main.xml  (Specific layout for Arabic)
    layout-ldrtl/  
        main.xml  (Any "right-to-left" language, except
                  for Arabic, because the "ar" language qualifier
                  has a higher precedence.)
    

    Note: To enable right-to-left layout features for your app, you must set supportsRtl to "true" and set targetSdkVersion to 17 or higher.

    0 讨论(0)
  • 2020-12-31 12:33

    Add direction- and language-specific resources

    This step involves adding specific versions of your layout, drawables, and values resource files that contain customized values for different languages and text directions.

    In Android 4.2 (API level 17) and higher, you can use the -ldrtl (layout-direction-right-to-left) and -ldltr (layout-direction-left-to-right) resource qualifiers. To maintain backward compatibility with loading existing resources, older versions of Android use a resource's language qualifiers to infer the correct text direction.

    Suppose that you want to add a specific layout file to support RTL scripts, such as the Hebrew, Arabic, and Persian languages. To do this, you add a layout-ldrtl/ directory in your res/ directory, as shown in the following example:

    res/
        layout/
            main.xml //This layout file is loaded by default.
        layout-ldrtl/
            main.xml //This layout file is loaded for languages using an
                     //RTL text direction, including Arabic, Persian, and Hebrew.
    

    If you want to add a specific version of the layout that is designed for only Arabic text, your directory structure becomes the following:

    res/
        layout/
            main.xml //This layout file is loaded by default.
        layout-ar/
            main.xml //This layout file is loaded for Arabic text.
        layout-ldrtl/
            main.xml //This layout file is loaded only for non-Arabic
                     //languages that use an RTL text direction.
    

    Note: Language-specific resources take precedence over layout-direction-specific resources, which take precedence over the default resources.

    0 讨论(0)
  • 2020-12-31 12:34

    can we change our layout style when there is change of language.

    Yes. You can provide different layouts according to the language user chooses. This is clearly described in the Providing Resources documentation.

    Infact a specific layout qualifier is provided for supporting right-to-left-directed languages called res/layout-ldrtl.

    P.S: This attribute is only supported from API 17.

    0 讨论(0)
提交回复
热议问题