This is my code:
<EditText
android:layout_width="#dimen/edittext_width"
android:layout_height="#dimen/edittext_height"
android:gravity="right|center_vertical"/>
I want the text go from right, so I add this code: android:gravity="right".
The problem is that the cursor always remain at right.
I Attaching screen shots:
With gravity right -
Without gravity right -
Actually I want it will be like the first image and the last image.
Any help?
Try this .
android:gravity="right"
android:textAlignment="gravity"
Android offers support for right-to-left languages since Android 4.2. See this article on the Android developers blog.
With a few simple changes, your app will be automatically mirrored
when the user switches the system language to a right-to-left script
(such as Arabic, Hebrew, or Persian).
To take advantage of RTL layout mirroring, simply make the following changes to your app:
Declare in your app manifest that your app supports RTL mirroring.
Specifically, add android:supportsRtl="true" to the element in your manifest file.
Change all of your app's "left/right" layout properties to new "start/end" equivalents.
If you are targeting your app to Android 4.2 (the app's targetSdkVersion or minSdkVersion is 17 or higher), then you should use “start” and “end” instead of “left” and “right”. For example, android:paddingLeft should become android:paddingStart.
If you want your app to work with versions earlier than Android 4.2 (the app's targetSdkVersion or minSdkVersion is 16 or less), then you should add “start” and end” in addition to “left” and “right”. For example, you’d use both android:paddingLeft and android:paddingStart.
This could be caused due to the devices or emulators keyboard Locale, If it is set to a language that is not right to left it could override (someone correct me if I'm wrong here).
Related
i made this android:supportsRtl="false" for my application
and yet it still flip my layout views when i change the language from English to Arabic and verse versa any clues what to do to prevent the views from flipping not matter what language it runs on or API level
thanks
If targetSdkVersion is set to 16 or lower then it will ignore the RTL support. Otherwise if you change the language then it will support RTL.
As this attribute is supported from the API 17.
Ref Link: https://developer.android.com/guide/topics/manifest/application-element
I have developed an app in English language. When i change my android language to a right-to-left (later rtl) language , my app goes rtl layout but I don't want that. I want my app layout to stay left-to-right (later ltr) whether android language is ltr or rtl.
I know there is layoutdirection in a activity attributes but it's not for APIs below 17.
I'd still say to use this:
Add in styles.xml in your Base App theme style:
<item name="android:layoutDirection">ltr</item>
17+ is legitimate.
Just do this in manifest
android:supportsRtl="false"
with support rtl your layout in english is still ltr.
rtl is on only for languages how japanese and so on.
the most devices are already API 17+.
On emulator or device you can change main language, so you can use rtl or rtl layout depend on selected language.
Try to put all of your resources (layouts, strings, drawable ... etc) in rtl language folder like
layout-ar and remove default layout folder
also use values-ar, drawable-ar .... etc only
i think this will force android to read from it.
I use Android Studio's Navigation Drawer Activity in My Application but when I change Language of System to Right to Left Language My Application's UI vary
Left to right(My main UI)
Right to left
I want to stay the same upon language change
What can I do?
If your API is 17+ you can use the:android:supportsRtl="true"
in the manifest
If you want your views to remain same set android:supportsRtl="false" for API level 17+. And make sure you are not using start and end as gravity values to any view.Because start and end are used for applications supporting RTL.Instead use left and right.
If you want your views to change according to language then set android:supportsRtl="true" and set gravity values as start and end instead of left and right.
Note: start and end only works with device supporting API level 17+.
For more reference see This blog.
Just set android:supportsRtl="#string/is_rtl" for your application node in the manifest and you are good to go.
I have a custom video player Activity.
I am forced to enable RTL Support in my Application.
But doing so will result in a Right-To-Left aligned ProgressBar. (And that looks ugly)
I want my ProgressBar to stay LTR in my RTL enabled Application.
Is there any solution?
P.S. I am using Android 4.2.2
Okay there is a simple solution for 4.2 and higher:
You can set the android:layoutDirection property in XML, it can have either rtl or ltr values.
The property overrides android:supportsRtl property in "application" segment of your manifest file.
I have an edittext in my application that will show the cursor correctly in Froyo or Gingerbread, however in later sdks the cursor is invisible. I have found online the solution is to set the android:textCursorDrawable="#null" so that the edittext will use the font color for the cursor. However, since my minsdkversion is 8, I do not have access to that property.
Is their either a way to selectively add a property based on the sdk you are on? Or possibly a way to work around this so that I can have visible cursors on both older and newer sdk versions?
I don't know your current setup, but one way to use that property is to use different layouts folders based on various android versions. android:textCursorDrawable is a property introduced in API 12 so you could have a layout folder like layout-v12 which will be used where the API is 12 or greater. In the layouts from this folder the use of the property is valid.
For lower versions, Froyo and Gingerbread, you don't have any problems so you would use a default folder, layout. In the end you'll have two layouts folder(containing the same layout files):
layout // don't need the property
layout-v12 // use the property
That leaves out API 11, I don't know if this is a deal breaker for you.
Try setting your targetSdkVersion to API level 13 or higher to gain access to the android:textCursorDrawable property
If you not has a cursor I guess the input is simple and say you only can enter new chars at end of the text?
I think you can use a TextView and to this add you own KeyListener?
But in this case you will has problem with the virtual keyboard not is show, see some of this links:
Forcing the Soft Keyboard open
android force keyboard visible
or create you own keyboard if the rang of valid keys is very limit as only digits.