android rtl support,【Android】Native RTL support in Android 4.2

Android 4.1 (Jelly Bean) introduced limitedsupport for bidirectional textinTextViewandEditTextelements, allowing apps to display and edit text in both left-to-right (LTR) and right-to-left (RTL) scripts. Android 4.2 addedfull 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:

3b3cae272037a5653c37fcd4868b0021.png   

7e1ece02370b61c40cb50db8ce660dbc.png

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

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

Specifically, addandroid:supportsRtl="true"to theelement in your manifest file.

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,HierarchyViewernow 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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值