Punctuation Mark rendered at start of LTR text in RTL OS












0















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)










share|improve this question





























    0















    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)










    share|improve this question



























      0












      0








      0








      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)










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 14:07







      yash mittal

















      asked Nov 14 '18 at 10:52









      yash mittalyash mittal

      154




      154
























          1 Answer
          1






          active

          oldest

          votes


















          0














          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:





          1. end these texts with &lrm; symbol:



            android:text="Hello!u200e"


          2. choose "ltr" textDirection for these fields.

          3. 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.


          4. 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"
            />







          share|improve this answer


























          • 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: 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













          • This is not what I see. Maybe, this depends on the platform, I cannot tell.

            – Alex Cohn
            Nov 14 '18 at 21:48











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          0














          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:





          1. end these texts with &lrm; symbol:



            android:text="Hello!u200e"


          2. choose "ltr" textDirection for these fields.

          3. 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.


          4. 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"
            />







          share|improve this answer


























          • 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: 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













          • This is not what I see. Maybe, this depends on the platform, I cannot tell.

            – Alex Cohn
            Nov 14 '18 at 21:48
















          0














          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:





          1. end these texts with &lrm; symbol:



            android:text="Hello!u200e"


          2. choose "ltr" textDirection for these fields.

          3. 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.


          4. 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"
            />







          share|improve this answer


























          • 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: 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













          • This is not what I see. Maybe, this depends on the platform, I cannot tell.

            – Alex Cohn
            Nov 14 '18 at 21:48














          0












          0








          0







          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:





          1. end these texts with &lrm; symbol:



            android:text="Hello!u200e"


          2. choose "ltr" textDirection for these fields.

          3. 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.


          4. 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"
            />







          share|improve this answer















          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:





          1. end these texts with &lrm; symbol:



            android:text="Hello!u200e"


          2. choose "ltr" textDirection for these fields.

          3. 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.


          4. 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"
            />








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 '18 at 21:53

























          answered Nov 14 '18 at 16:35









          Alex CohnAlex Cohn

          41.3k552188




          41.3k552188













          • 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: 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













          • 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













          • 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











          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine