Android 4.2 supports native RTL (display from right to left)

Source: Internet
Author: User
04 March 2013

Http://android-developers.blogspot.com/2013/03/native-rtl-support-in-android-42.html

HtT
Pandroid-developers.blogspot.com/2013/03/native-rtl-support-in-android-42.html

Native RTL support in Android 4.2. Posted by Fabrice di meglio, Android frameworks team

Android 4.1 (jelly bean) introduced limited support for Bidirectional text in textview and edittext elements,
Allowing apps to display and edit text in both left-to-right (LTr) and right-to-left (RTL) scripts. Android 4.2 added full
Native support for RTL layouts, including layout locking ing, allowing you to deliver the same great app experience to all of your users, whether their language uses a script that reads right-to-left or one that reads left-to-right.

If you do nothing, your app will not change-it will continue to appear as it currently does. however, with a few simple changes, your app will be automatically mirrored when the user switches the system language to a right-to-left script (such as Arabic,
Hebrew, or Persian). For example, see the following screenshots of the Settings app:

To take advantage of RTL layout locking ing, simply make the following changes to your app:

  1. Declare in your app manifest that your app supports RTL signing ing.

    Specifically, addandroid:supportsRtl="true"To<application>Element
    In your manifest file.

  2. Change all of your app's "left/right" layout properties to new "Start/end" equivalents.
    • If you are targeting your app to Android 4.2 (the app'stargetSdkVersionOrminSdkVersionIs 17 or higher), then you
      Shocould use "START" and "end" instead of "left" and "right". For example,android:paddingLeftShocould becomeandroid:paddingStart.
    • If you want your app to work with versions earlier than Android 4.2 (the app'stargetSdkVersionOrminSdkVersionIs 16 or less ),
      Then you shoshould Add "START" and end"In addition"Left" and "right". For example, you 'd use bothandroid:paddingLeftAndandroid:paddingStart.

For more precise control over your app UI in both LTR and RTL mode, Android 4.2 includes des the following new APIs to help manage view components:

  • Android: layoutdirection-
    Attribute for setting the direction of a component's layout.
  • Android: textdirection-attribute
    For setting the direction of a component's text.
  • Android: textalignment-attribute
    For setting the alignment of a component's text.
  • Getlayoutdirefromlocale ()-
    Method for getting the locale-specified direction

You can even create custom versions of layout, drawables, and other resources for display when a right-to-left script is in use. simply use the resource qualifier"ldrtl"To tag your resources, meaning" layout direction right-to-left ". To debug
And optimize custom right-to-left layouts, hierarchyviewer now lets you see start/end properties, Layout
Direction, text direction, and text alignment for all the views in the hierarchy.

It's now easy to create beautiful Android apps for all your users, whether they use a right-to-left or left-to-right language. we look forward to seeing some great apps!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.