Punctuation Mark rendered at start of LTR text in RTL OS
Consider the snippet:
<TextView
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:text="Hello!"
android:textDirection="locale"/>
The code results in "!Hello" as displayed output instead of expected "Hello!" when OS language is set to RTL.
This is observed only with textDirection set to "locale", otherwise, the text gets displayed properly.
I need to set TextDirection as locale so that the text is aligned in the textview according to the OS locale.
Is there a way to be able to use textdirection as locale without messing the text rendering or any other simple solution to achieve the same effect.
PS: I wish to apply this at a global level to all textviews and hence can't use textAlignment(as viewStart) as that would mess with the gravity property set on the views. (specifically, Gravity set as center horizontal would be ignored in favor of textalignment = viewStart)
android android-layout android-textview right-to-left text-alignment
add a comment |
Consider the snippet:
<TextView
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:text="Hello!"
android:textDirection="locale"/>
The code results in "!Hello" as displayed output instead of expected "Hello!" when OS language is set to RTL.
This is observed only with textDirection set to "locale", otherwise, the text gets displayed properly.
I need to set TextDirection as locale so that the text is aligned in the textview according to the OS locale.
Is there a way to be able to use textdirection as locale without messing the text rendering or any other simple solution to achieve the same effect.
PS: I wish to apply this at a global level to all textviews and hence can't use textAlignment(as viewStart) as that would mess with the gravity property set on the views. (specifically, Gravity set as center horizontal would be ignored in favor of textalignment = viewStart)
android android-layout android-textview right-to-left text-alignment
add a comment |
Consider the snippet:
<TextView
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:text="Hello!"
android:textDirection="locale"/>
The code results in "!Hello" as displayed output instead of expected "Hello!" when OS language is set to RTL.
This is observed only with textDirection set to "locale", otherwise, the text gets displayed properly.
I need to set TextDirection as locale so that the text is aligned in the textview according to the OS locale.
Is there a way to be able to use textdirection as locale without messing the text rendering or any other simple solution to achieve the same effect.
PS: I wish to apply this at a global level to all textviews and hence can't use textAlignment(as viewStart) as that would mess with the gravity property set on the views. (specifically, Gravity set as center horizontal would be ignored in favor of textalignment = viewStart)
android android-layout android-textview right-to-left text-alignment
Consider the snippet:
<TextView
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:text="Hello!"
android:textDirection="locale"/>
The code results in "!Hello" as displayed output instead of expected "Hello!" when OS language is set to RTL.
This is observed only with textDirection set to "locale", otherwise, the text gets displayed properly.
I need to set TextDirection as locale so that the text is aligned in the textview according to the OS locale.
Is there a way to be able to use textdirection as locale without messing the text rendering or any other simple solution to achieve the same effect.
PS: I wish to apply this at a global level to all textviews and hence can't use textAlignment(as viewStart) as that would mess with the gravity property set on the views. (specifically, Gravity set as center horizontal would be ignored in favor of textalignment = viewStart)
android android-layout android-textview right-to-left text-alignment
android android-layout android-textview right-to-left text-alignment
edited Nov 14 '18 at 14:07
yash mittal
asked Nov 14 '18 at 10:52
yash mittalyash mittal
154
154
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
There is nothing special about "locale"
, same display occurs when you use "rtl"
for textDirection of a field which has LTR text ending with !
. Or .
, or any other punctuation with no strong directionality.
What can be done:
end these texts with
‎
symbol:android:text="Hello!u200e"
- choose
"ltr"
textDirection for these fields. - at runtime, identify the test fields that start with LTR sequence, or contain only LTR sequence (this logic deoends on your choice), and apply rules 1. or 2. (above) to these fields.
use
android:textAlignment="viewStart"
instead:<FrameLayout
android:layoutDirection="rtl" ...>
<TextView
android:text="Hello!"
android:textAlignment="viewStart"
android:layout_width="80dp"
android:padding="12dp"
android:background="@android:color/black"
android:textColor="@android:color/white"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
option 2 is no good as that forces the text to align to left.( I want the text alignment to come from locale). Also, it is not feasible to write this dynamic resolution logic for every textview.
– yash mittal
Nov 14 '18 at 20:59
Can i avoid using textDirection at all? My motive to use textDirection as "locale" was to make text align as per the OS locale( both LTR and RTL text should be right aligned in RTL).
– yash mittal
Nov 14 '18 at 21:09
You can set right alignment without choosing textDirection: tryandroid:textAlignment="viewStart"
for RTL locale.
– Alex Cohn
Nov 14 '18 at 21:25
like I mentioned in the question description, certain textview elements may have gravity set to center..for them, both LTR and RTL text should remain in center. Specifying textAlignment as viewStart would override that gravity property and align the text to viewStart.
– yash mittal
Nov 14 '18 at 21:29
This is not what I see. Maybe, this depends on the platform, I cannot tell.
– Alex Cohn
Nov 14 '18 at 21:48
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298487%2fpunctuation-mark-rendered-at-start-of-ltr-text-in-rtl-os%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There is nothing special about "locale"
, same display occurs when you use "rtl"
for textDirection of a field which has LTR text ending with !
. Or .
, or any other punctuation with no strong directionality.
What can be done:
end these texts with
‎
symbol:android:text="Hello!u200e"
- choose
"ltr"
textDirection for these fields. - at runtime, identify the test fields that start with LTR sequence, or contain only LTR sequence (this logic deoends on your choice), and apply rules 1. or 2. (above) to these fields.
use
android:textAlignment="viewStart"
instead:<FrameLayout
android:layoutDirection="rtl" ...>
<TextView
android:text="Hello!"
android:textAlignment="viewStart"
android:layout_width="80dp"
android:padding="12dp"
android:background="@android:color/black"
android:textColor="@android:color/white"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
option 2 is no good as that forces the text to align to left.( I want the text alignment to come from locale). Also, it is not feasible to write this dynamic resolution logic for every textview.
– yash mittal
Nov 14 '18 at 20:59
Can i avoid using textDirection at all? My motive to use textDirection as "locale" was to make text align as per the OS locale( both LTR and RTL text should be right aligned in RTL).
– yash mittal
Nov 14 '18 at 21:09
You can set right alignment without choosing textDirection: tryandroid:textAlignment="viewStart"
for RTL locale.
– Alex Cohn
Nov 14 '18 at 21:25
like I mentioned in the question description, certain textview elements may have gravity set to center..for them, both LTR and RTL text should remain in center. Specifying textAlignment as viewStart would override that gravity property and align the text to viewStart.
– yash mittal
Nov 14 '18 at 21:29
This is not what I see. Maybe, this depends on the platform, I cannot tell.
– Alex Cohn
Nov 14 '18 at 21:48
add a comment |
There is nothing special about "locale"
, same display occurs when you use "rtl"
for textDirection of a field which has LTR text ending with !
. Or .
, or any other punctuation with no strong directionality.
What can be done:
end these texts with
‎
symbol:android:text="Hello!u200e"
- choose
"ltr"
textDirection for these fields. - at runtime, identify the test fields that start with LTR sequence, or contain only LTR sequence (this logic deoends on your choice), and apply rules 1. or 2. (above) to these fields.
use
android:textAlignment="viewStart"
instead:<FrameLayout
android:layoutDirection="rtl" ...>
<TextView
android:text="Hello!"
android:textAlignment="viewStart"
android:layout_width="80dp"
android:padding="12dp"
android:background="@android:color/black"
android:textColor="@android:color/white"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
option 2 is no good as that forces the text to align to left.( I want the text alignment to come from locale). Also, it is not feasible to write this dynamic resolution logic for every textview.
– yash mittal
Nov 14 '18 at 20:59
Can i avoid using textDirection at all? My motive to use textDirection as "locale" was to make text align as per the OS locale( both LTR and RTL text should be right aligned in RTL).
– yash mittal
Nov 14 '18 at 21:09
You can set right alignment without choosing textDirection: tryandroid:textAlignment="viewStart"
for RTL locale.
– Alex Cohn
Nov 14 '18 at 21:25
like I mentioned in the question description, certain textview elements may have gravity set to center..for them, both LTR and RTL text should remain in center. Specifying textAlignment as viewStart would override that gravity property and align the text to viewStart.
– yash mittal
Nov 14 '18 at 21:29
This is not what I see. Maybe, this depends on the platform, I cannot tell.
– Alex Cohn
Nov 14 '18 at 21:48
add a comment |
There is nothing special about "locale"
, same display occurs when you use "rtl"
for textDirection of a field which has LTR text ending with !
. Or .
, or any other punctuation with no strong directionality.
What can be done:
end these texts with
‎
symbol:android:text="Hello!u200e"
- choose
"ltr"
textDirection for these fields. - at runtime, identify the test fields that start with LTR sequence, or contain only LTR sequence (this logic deoends on your choice), and apply rules 1. or 2. (above) to these fields.
use
android:textAlignment="viewStart"
instead:<FrameLayout
android:layoutDirection="rtl" ...>
<TextView
android:text="Hello!"
android:textAlignment="viewStart"
android:layout_width="80dp"
android:padding="12dp"
android:background="@android:color/black"
android:textColor="@android:color/white"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
There is nothing special about "locale"
, same display occurs when you use "rtl"
for textDirection of a field which has LTR text ending with !
. Or .
, or any other punctuation with no strong directionality.
What can be done:
end these texts with
‎
symbol:android:text="Hello!u200e"
- choose
"ltr"
textDirection for these fields. - at runtime, identify the test fields that start with LTR sequence, or contain only LTR sequence (this logic deoends on your choice), and apply rules 1. or 2. (above) to these fields.
use
android:textAlignment="viewStart"
instead:<FrameLayout
android:layoutDirection="rtl" ...>
<TextView
android:text="Hello!"
android:textAlignment="viewStart"
android:layout_width="80dp"
android:padding="12dp"
android:background="@android:color/black"
android:textColor="@android:color/white"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
edited Nov 14 '18 at 21:53
answered Nov 14 '18 at 16:35
Alex CohnAlex Cohn
41.9k553191
41.9k553191
option 2 is no good as that forces the text to align to left.( I want the text alignment to come from locale). Also, it is not feasible to write this dynamic resolution logic for every textview.
– yash mittal
Nov 14 '18 at 20:59
Can i avoid using textDirection at all? My motive to use textDirection as "locale" was to make text align as per the OS locale( both LTR and RTL text should be right aligned in RTL).
– yash mittal
Nov 14 '18 at 21:09
You can set right alignment without choosing textDirection: tryandroid:textAlignment="viewStart"
for RTL locale.
– Alex Cohn
Nov 14 '18 at 21:25
like I mentioned in the question description, certain textview elements may have gravity set to center..for them, both LTR and RTL text should remain in center. Specifying textAlignment as viewStart would override that gravity property and align the text to viewStart.
– yash mittal
Nov 14 '18 at 21:29
This is not what I see. Maybe, this depends on the platform, I cannot tell.
– Alex Cohn
Nov 14 '18 at 21:48
add a comment |
option 2 is no good as that forces the text to align to left.( I want the text alignment to come from locale). Also, it is not feasible to write this dynamic resolution logic for every textview.
– yash mittal
Nov 14 '18 at 20:59
Can i avoid using textDirection at all? My motive to use textDirection as "locale" was to make text align as per the OS locale( both LTR and RTL text should be right aligned in RTL).
– yash mittal
Nov 14 '18 at 21:09
You can set right alignment without choosing textDirection: tryandroid:textAlignment="viewStart"
for RTL locale.
– Alex Cohn
Nov 14 '18 at 21:25
like I mentioned in the question description, certain textview elements may have gravity set to center..for them, both LTR and RTL text should remain in center. Specifying textAlignment as viewStart would override that gravity property and align the text to viewStart.
– yash mittal
Nov 14 '18 at 21:29
This is not what I see. Maybe, this depends on the platform, I cannot tell.
– Alex Cohn
Nov 14 '18 at 21:48
option 2 is no good as that forces the text to align to left.( I want the text alignment to come from locale). Also, it is not feasible to write this dynamic resolution logic for every textview.
– yash mittal
Nov 14 '18 at 20:59
option 2 is no good as that forces the text to align to left.( I want the text alignment to come from locale). Also, it is not feasible to write this dynamic resolution logic for every textview.
– yash mittal
Nov 14 '18 at 20:59
Can i avoid using textDirection at all? My motive to use textDirection as "locale" was to make text align as per the OS locale( both LTR and RTL text should be right aligned in RTL).
– yash mittal
Nov 14 '18 at 21:09
Can i avoid using textDirection at all? My motive to use textDirection as "locale" was to make text align as per the OS locale( both LTR and RTL text should be right aligned in RTL).
– yash mittal
Nov 14 '18 at 21:09
You can set right alignment without choosing textDirection: try
android:textAlignment="viewStart"
for RTL locale.– Alex Cohn
Nov 14 '18 at 21:25
You can set right alignment without choosing textDirection: try
android:textAlignment="viewStart"
for RTL locale.– Alex Cohn
Nov 14 '18 at 21:25
like I mentioned in the question description, certain textview elements may have gravity set to center..for them, both LTR and RTL text should remain in center. Specifying textAlignment as viewStart would override that gravity property and align the text to viewStart.
– yash mittal
Nov 14 '18 at 21:29
like I mentioned in the question description, certain textview elements may have gravity set to center..for them, both LTR and RTL text should remain in center. Specifying textAlignment as viewStart would override that gravity property and align the text to viewStart.
– yash mittal
Nov 14 '18 at 21:29
This is not what I see. Maybe, this depends on the platform, I cannot tell.
– Alex Cohn
Nov 14 '18 at 21:48
This is not what I see. Maybe, this depends on the platform, I cannot tell.
– Alex Cohn
Nov 14 '18 at 21:48
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298487%2fpunctuation-mark-rendered-at-start-of-ltr-text-in-rtl-os%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown