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:
- Get rid of the margin on the
p
tag:p { margin: 0; }
- Use a
div
instead of ap
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:
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
Android Studio:Failure [Install_Failed_Older_Sdk]
How to Use Postdelayed() Correctly in Android Studio
Drawable Folders in Res Folder
Turn Off Device Programmatically
Detect Power Button Long Press
How to Run Media Scanner in Android
Android Place Picker Closes Immediately After Launch
How to Listen to Doubletap on a View in Android
Android L's Ripple Effect - Touch Feedback for Buttons - Using Xml
How to Get Images Dynamically from Drawable Folder
Drag and Drop Items in Recyclerview with Gridlayoutmanager
Camera Preview Image Data Processing with Android L and Camera2 API
How to Create an Android Library Jar with Gradle Without Publicly Revealing Source Code