Cookienator
Cookienator

Reputation: 647

Text adaptation according to device language direction (LTR, RTL) on Android

I'm using font-awesome for some of my buttons. One of them is a "back" button. On LTR languages, I want the button to be an arrow that points to the left, and on RTL, an arrow that points to the right.

Right now what I'm doing is this: I'm holding two strings in my "values" folder

<string name="icon_back_ltr">&#xf060;</string>
<string name="icon_back_rtl">&#xf061;</string>
<color  name="icon_back_color">#FFFFFF</color>

Then, I check programatically if the device language is an RTL language. If so, I modify the text on the button accordingly.

My question is, is there a better way to do it? One that does not require checking for layout direction programatically? For example, I know I can define the word "Hello" to be in English (using "values") and then to be something else in Hebrew (using "values-iw). The question is, can I define a certain string to be text A in all LTR languages and then to be text B in all RTL languages?

Upvotes: 2

Views: 899

Answers (1)

Malwinder Singh
Malwinder Singh

Reputation: 7040

Define two reource driectories values-ldrtl (means "layout-direction-right-to-left") and values-ldltr (means "layout-direction-left-to-right"). Declare in your app manifest that your app supports RTL mirroring. Specifically, add android:supportsRtl="true" to the <application> element in your manifest file and set targetSdkVersion to 17 or higher.

Upvotes: 4

Related Questions