How can set rtl=false , just for a layer? - android

I want to set rtl = true in Manifest for all layers , except one of the layers .
how can do it ?

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 think for all layers you need to define rtl = true and for one layer make it false. That should work.

Related

Setting layoutdirection with supportsrtl=false

I have an application on which I do not have the liberty to add supportsRtl = true
With that being set to false I have two questions.
1) Is it possible to set supportsRtl true programatically?
2) This is the code that doesn't work when supportsRtl = false
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
Any ideas as to how can I have a single layout file be displayed in ltr/rtl while the supportsRtl is false?
Setting only one layout direction to RTL wouldn't be a good idea since users who uses RTL direction will need to see the right texts direction for all Activities-layouts.
Just set the android:supportsRtl="true" in the AndroidManifest.xml then go to:
Refactor -> Add RTL Support Where Possible
This will satisfy your need by adding RTL to where it's possible.
About that start-end attributes in the xml side, all you need to do is:
Right-click on the project -> Replace in Path
Then replacing your start-end attributes easily by using this.

Ltr for Persian locale in android

I am developing an app which supports two languages: English("en") and Persian("fa"). I have set android:supportsRtl="false" in AndroidManifest.xml since I need everything to be from left to right. I set margins for all views that I have but for the ones containing a string, it is not working right and it still seems like it is setting the directions from right to left. How can I fix that? I also tried changing the layoutDirection manually to left to right but that did not work either.
You must handle your locale in all activities. Android by default uses the locale of the device to select the appropriate language dependent resources.
Also you must consider project minimum sdk. I recommended to you change it to 16 or higher: minSdkVersion 16
Maybe this link help you.
I set margins for all views that I have but for the ones containing a string, it is not working right
For this for example you must use from android:layout_marginEnd instead of android:layout_marginRight. Also in default create your layout for en locale and then handle and change it by app locale to fa or another locale.
You have to use instead of the right from the end and instead of the left from the start
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="تست"
android:gravity="start"/>

How to set default/fallback value in Android?

How to set default/fallback value in order to see something in layout preview, when attributes are set by style?
You can use Design-time view attributes.
From the documentation:
You can insert sample data in your layout preview by using the tools:
prefix instead of android: with any attribute from the Android
framework. This is useful when the attribute's value isn't populated
until runtime but you want to see the effect beforehand, in the layout
preview.
For example, if the android:text attribute value is set at runtime or
you want to see the layout with a value different than the default,
you can add tools:text to specify some text for the layout preview
only.

RTL properties with padding attribute android

I am working on an android application and provided support for RTL feature in my application.
Now when I define any marginLeft Property, I define the same marginStart property also on that view to have the same with RTL languages.
If I define margin attribute (margin attribute contains : marginTop, marginLeft, marginRight and marginBottom), so this attribute already contains Left and Right margins, so should I need to define marginStart and marginEnd properties as well on this view, or it'll be automatically work on that.
Please help if anyone have any idea about this.
In places you use both marginLeft and marginRight you don't need to add marginStart/marginEnd.
You should use Start/End when you define one side only.
If your app only supports API ≥ 17, replace all the layout_marginLeft/layout_marginReft/paddingLeft/paddingRight or any other Left and Right layout property with Start and End equivalent. For example android:paddingLeft will be replaced with android:paddingStart.
If your app supports API<17 then instead of replacing the Left and Right layout properties, add their Start and End layout property equivalent alongside.

Setting attribute values dynamically

There are always a few attribute values that Android doesn't explicitly define how to change and set dynamically for views. In my case, I'm trying to set the ListView's vertical scroll bar drawable. There's no method in the ListView class that lets you set this. I can only define this in the XML using android:scrollbarThumbVertical="#drawable/new_scroll_bar". Is there ANY workaround that would let me change attributes not otherwise defined dynamically?
It seems impossible, since the document doesn't refer to a corresponding method to set that XML attribute.
In the docs it says it corresponds to the global resource attribute:
android.R.attr.scrollbarThumbHorizontal
You can set this equal to a drawable programatically.
Ref: http://developer.android.com/reference/android/view/View.html#attr_android:scrollbarThumbVertical
Let me know if that is what you were trying to get to.

Categories

Resources