Clans / FloatingActionButton

Android Floating Action Button based on Material Design specification
Apache License 2.0
5.23k stars 1.13k forks source link

RTL support #115

Open adek opened 9 years ago

adek commented 9 years ago

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.

jndefosse commented 9 years ago

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?

adek commented 9 years ago

@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.

FarajiMehrdad commented 8 years ago

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.

amorenew commented 8 years ago

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

dawidhyzy commented 8 years ago

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"

mehulTank commented 6 years ago

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

mehulTank commented 6 years ago

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

dawidhyzy commented 6 years ago

@mehulTank what you mean by parametrically?