How to Make the Text Direction from Right to Left

Android RTL Text Direction

Adding android:textDirection="locale" to the TextView and android:supportsRtl="true" will do the trick. However, textDirection="locale" changes the direction in order to locale which is en or fa or it is ar. (Depends on device's language)

And to be clear enough, it's working properly because the text you have in the TextView is LTR and you used RTL direction which as you can see, it made the direction RTL and there is no problem with that. Also, using android:gravity="start" will probably force it to use from start which I suppose, it will start from LTR. (I'd suggest removing android:gravity="start" and let the Android(In order to device's language) decide which one is the best)

So, to test if it is working or not, you can set the text to arabic or persian language as follows:

android:text="این یک تست است"

If it started from RTL and with "این", so it works as expected.

How to change input text direction from right to left

You can rotate text container

CSS

.text-rotated {
transform: rotate(180deg)
}

Or another way in JS

var p = document.querySelector('p');

var reversed = p.innerText.split('').reverse().join('');

p.innerText = reversed;

Example JSFiddle

How do I get my text to be direction from right to left without using a p tag?

You have two options here:

  1. Get rid of the margin on the p tag: p { margin: 0; }
  2. Use a div instead of a p

Most browsers render paragraph tags with a 1em top and bottom margin.

As for your problems with the rtl property, what browser are you using? As far as I'm aware it should work fine with as long as the element is inline and you're using the correct unicode characters.

Change text direction to become right-to-left in R Markdown

You can add css options to your Rmd template file. For example:

---
title: חוכמה
output: html_document
---
<style>
h1 {
direction: rtl;
}
p {
direction: rtl;
}
</style>

הספר הוא ידידו הטוב של האדם

Render this document with rmarkdown::render("Template.Rmd") for a result like this:

Sample Image

Option direction: rtl; specifies text direction right to left.

p in :

p {
direction: rtl;
}

Specifies direction for text in "paragraphs".

h1 in:

h1 {
direction: rtl;
}

Specifies direction for level 1 header (it's your title and header that starts with 1 #). For direction to work with all headers (eg, #, ##, ###) you should use:

h1, h2, h3, h4, h5, h6 {
direction: rtl;
}


Related Topics



Leave a reply



Submit