FloatingActionButton icon indicating copy to clipboard operation
FloatingActionButton copied to clipboard

RTL support

Open adek opened this issue 9 years ago • 8 comments

Have you been thinking about adding support for RTL (Right-to-Left) languages? I'm using your library and it's great. Now my users wanted support for RTL languages (Arabic etc...). The FAB from Google Support Deisign library is working great here. If you are using RTL language on your phone the FAB is on the left.

Your library is always showing button on the right side (which is wrong).

Or maybe I miss something. Settings layout_gravity is not working.

The problem is with FAB with menu.

adek avatar Aug 31 '15 18:08 adek

Did you try to change "fab:menu_labels_position" value on your layout : By defaulft, it's left but if you change the value to right (fab:menu_labels_position="right"), that's solve your problem, no?

jndefosse avatar Sep 02 '15 12:09 jndefosse

@jndefosse No. Not at all. Layout should use these features: http://android-developers.blogspot.com/2013/03/native-rtl-support-in-android-42.html

If you try to create layouts for RTL languages you'll see how this works.

FAB from Design Support Library works great.

I think that this should be part of the library. If users is using RTL layout FAB should be moved by default to let.

adek avatar Sep 02 '15 13:09 adek

I set app:menu_labels_position="right" and app:layout_anchor="@id/vpPager" app:layout_anchorGravity="bottom | left | start"

and everything is right in RTL language.

FarajiMehrdad avatar Oct 04 '15 13:10 FarajiMehrdad

simple fix in FloatingActionMenu i put this

public static boolean isRTL() {
        return isRTL(Locale.getDefault());
    }

    public static boolean isRTL(Locale locale) {
        final int directionality = Character.getDirectionality(locale.getDisplayName().charAt(0));
        return directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
                directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC;
    }

then in init

if (isRTL()) {
            mLabelsPosition = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_position, LABELS_POSITION_RIGHT);
        } else {
            mLabelsPosition = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_position, LABELS_POSITION_LEFT);
        }

in my fork https://github.com/amorenew/FloatingActionButton

amorenew avatar Aug 16 '16 08:08 amorenew

You can add to integer resources value with the position. LTR languages:

<resources>
    <integer name="fab_menu_position">0</integer>
</resources>

RTL languages:

<resources>
    <integer name="fab_menu_position">1</integer>
</resources>

then in FloatingActionMenu: app:menu_labels_position="@integer/fab_menu_position"

dawidhyzy avatar Aug 17 '16 11:08 dawidhyzy

How can set it programetically ? because if arabic then it is display in right other wise i want to disply on left side

mehulTank avatar Jun 16 '18 07:06 mehulTank

@dawidhyzy i have tried you mention sorry but it is not work for me

mehulTank avatar Jun 16 '18 07:06 mehulTank

@mehulTank what you mean by parametrically?

dawidhyzy avatar Jun 18 '18 12:06 dawidhyzy