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 mirroring, 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 mirroring, simply make the following changes to your app:

  1. Declare in your app manifest that your app supports RTL mirroring.

    Specifically, addandroid:supportsRtl="true"to the <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 should use “start” and “end” instead of “left” and “right”. For example,android:paddingLeftshould becomeandroid:paddingStart.
    • If you want your app to work with versions earlier than Android 4.2 (the app'stargetSdkVersionorminSdkVersionis 16 or less), then you should add “start” and end” in addition to “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 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.
  • getLayoutDirectionFromLocale() — 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!

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. MSSQL批量替换语句 在SQL SERVER中批量替
  2. sqlserver 行列互转实现小结
  3. mssql 数据库表行转列,列转行终极方案
  4. SQL效率提升之一些SQL编写建议并有效利用
  5. SQL语句实现删除ACCESS重复记录的两种方
  6. 教你几种在SQLServer中删除重复数据方法
  7. 数据结构简明备忘录 线性表
  8. SQL对冗余数据的删除重复记录只保留单条
  9. 一次SQL调优数据库性能问题后的过程(300W
  10. 根据日期知道当天是星期几的手动计算方法