0

How to create Rtl ViewPager with both En and Arabic locale?

I am using this code :

https://github.com/diego-gomez-olvera/RtlViewPager

but i cannot implement both locale.

hamed golbahar
  • 139
  • 1
  • 8

2 Answers2

0

Look at this line in RtlViewPager's source. It controls whether the RtlViewPager is in right-to-left mode.

If you extend RtlViewPager and override this method to always return true, the English locale should also appear as RTL.

For example:

public class AlwaysRtlViewPager extends RtlViewPager {
    public AlwaysRtlViewPager(Context context) {
        super(context);
    }

    public AlwaysRtlViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected boolean isRtl() {
        return true;
    }
}

Just replace your usages of RtlViewPager with this sub-class and you should get the desired result.

npace
  • 4,218
  • 1
  • 25
  • 35
  • Sir , how to create any Fragment in this code : [link] (https://github.com/diego-gomez-olvera/RtlViewPager) , can you help me? – hamed golbahar Jul 14 '16 at 20:44
0

You don't need any third party library. Android jetpack recently added new UI component called ViewPager2 which supports RTL Layout.

https://developer.android.com/jetpack/androidx/releases/viewpager2

The below answer talks about Migration guide and sample github app to support RTL view pager.

https://stackoverflow.com/a/59558911/651377

Alok Gupta
  • 1,806
  • 22
  • 21