RTL properties with padding attribute android - 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.

Related

Relative Layout alignParentLeft vs alignParentStart [duplicate]

This question already has answers here:
What is the difference between Android margin start/end and right/left?
(3 answers)
Closed 5 years ago.
So I am comfortable with using relative layouts, but whilst getting used to Android Studio I noticed that in my relative layout child views it generated both of the following.
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true
I have checked out the Android docs here, but cannot see a distinction between the two. Certainly swapping one for another in the Android Studio shows no visible difference. Is there one?
It depends on the layout direction. The layout direction can be either left-to-right (start = left, end = right), or right-to-left (vice versa).
By default, the layout direction is based on the locale (left-to-right for languages like English, right-to-left for languages like Arabic), but you can override it with the layoutDirection XML attribute or setLayoutDirection function. e.g.:
android:layoutDirection="ltr"
^ will make alignParentStart equivalent to alignParentLeft on all devices.
android:layoutDirection="rtl"
^ will make alignParentStart equivalent to alignParentRight on all devices. You can also set to "locale" to use the locale or "inherit" to inherit the layout direction from the parent view.
You need to add android:supportsRtl="true" to your AndroidManifest.xml to support right-to-left layouts.
also related: android:textDirection
android:layout_alignParentStart="true"
Aligns the start edge of this view to the start edge of its parent. This is the left edge for LTR (left to right) locales and the right one on RTL (right to left) locale languages like Arabic, Hebrew, Persian etc.
The reason Android Studio also adds
android:layout_alignParentLeft="true"
to your views is to support older platforms that came before 4.2.x Jelly Bean. The Start/End attributes like layout_alignParentStart are only available from API 17 onwards. The newer platforms fallback to Left/Right attributes only if the corresponding Start/End attributes are not found.
In case, your application supports legacy platforms using android:minSdkVersion below level 17 you must always provide Left/Right attributes for your views. Otherwise the project won't compile with an error message like
To support older versions than API 17 (project specifies 7)
you should also add android:layout_alignParentLeft="true"
Also note that your Android application needs to declare its support for RTL locales within your AndroidManifest.xml as well.
<application
...
android:supportsRtl="true"
/>
These "xxxStart", "xxxEnd" attribute is to support RTL(Right to Left) layout in some locales.
Such as
android:paddingStart
android:paddingEnd
android:layout_marginStart
android:layout_marginEnd
...
You can see more here about it.
In normal(left to right) layout, "xxxStart" means "xxxLeft" and "xxxEnd" means "xxxRight".But in Right to Left layout, "xxxStart" means "xxxRight" and "xxxEnd" means "xxxLeft".
But RTL is only supported on sdk 17 and higher.
To support lower sdk, you can use "android:layout_marginStart" along with "android:layout_marginLeft". At the lower sdk devices, "android:layout_marginLeft" will be used.

How to set margin for all TextView using styles.xml

I've read from another post that it's possible to set attributes like color to every TextView in an application: Setting global styles for Views in Android. However, I can't set layout_margin nor layout_height and layout_width attribute using that method to any textView, using "android:textviewStyle". On the other hand, if I use the style attribute and reference it to a style with all the attributes above, it works. Is there a way that you can use global styles and still set margin?
Thank you in advance
You can set padding instead of margin and you will have the same result.

Style Top & Bottom Part of Divider for Tab Widget

I have a TabWidget and I'm trying to style the divider. (See image above)
I set the Divider Drawable of the TabWidget but the top & bottom part is unchanged. I can't figure out how to style it.
All you need to do is set the dividerPadding attribute to 0dp in your TabWidget.
android:dividerPadding="0dp"
Also, maybe consider switching to ActionBar.Tabs instead, just considering TabWidget is deprecated.
It seems that Holo theme has default 16 pixels dividerPadding for each TabWidget.
I try to set it to zero in the XML but it is not working.
Fortunately, it works for me to set it dynamically as below
myTabHost.getTabWidget().setDividerPadding(0);
Note: I am using android.support.v4.app.FragmentTabHost
are you talking about grey bars on the top and the bottom of the divider? use fill_parent for the drawable's height and width if that is the case!

How to set default Android padding to an element without padding?

Let's say I just added two standard widgets -- CheckBox and CheckedTextView. The first one has nice, clear padding despite that fact I didn't set any, and there is no padding set in .xml file. The other one comes without any padding.
Now, I could get the value (fixed) of the padding from CheckBox by trial&error. But my question is how to set it in kind of dynamic fashion -- i.e. if in Android 7.0 padding for CheckBox will be "20sp" and I set "10sp" (because it is now 10sp -- I am making this up) then my two widgets would be with different paddings.
And I would like to have a consistent padding. So how to set something like "?android/default_padding" for padding?
Clarification: I am interested in using the system default padding, not hardcoding the same value made up by me over all widgets.
I looked it up for you, in API Level 10 (and also on every other Android platform) Android uses 9-Patch images with prefdefined paddings (there is no padding declared in the Selector), e.g. I mesured the checkbox and it as this pasddings: left, right: 6dp; top, bottom: 12dp. And the default button has a padding of 10dp; so there is no default padding as far as I can tell. But 10dp is good in most cases. Also, it just really depends on the screensize of your device. You will have to declare your own prefered padding like Daniel suggested. E.g: In your Values file 10dp and in values-large maybe 15.
Edit:
Here is the default checkbox for mdpi on Android 2.3.3:
You could create in your resources an xml file called dimens.xml, and the add something like this:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<dimen name="default_padding">10dp</dimen>
</resources>
Then you call from your layout something like this:
android:padding="#dimen/default_padding"
I think this is a consistent way of working :)
Good Luck!!!

Android, how to add some right padding to text in a spinner?

I'm developing an Android app (API level 8).
How do I add some right padding to the style of spinners layout?
With the default (Theme.black) style, the right arrow box is placed too close to the end of text in the (closed) spinner.
In your xml, use the android:paddingRight attribute.
In your XML file for the layout, use, for example
android:layout_marginLeft="5dip"

Categories

Resources