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