I have an Android app that has tabs. I want the app to be Right to Left.
I put android:supportsRtl="true" in the manifest file, and changed some of the elements to be android:layoutDirection="rtl".
It changes everything to right to left, which is what I want, except that it reversed the swiping direction in the tabs- when you swipe to the left, it moves to the left tab, instead of the opposite from the swipe. I want to change it to make it a regular swipe.
This is my code:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:fitsSystemWindows="true"
android:id="@+id/drawer_layout">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layoutDirection="rtl">
<include
android:id="@+id/toolbar"
android:gravity="right"
layout="@layout/toolbar" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/main_layout"
android:layout_below="@id/toolbar">
<com.refractored.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:textColor="#ecf0f1"
app:pstsShouldExpand="true"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:context=".MainActivity" />
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/nav_view"
android:layoutDirection="rtl"
app:headerLayout="@layout/header"
app:menu="@menu/nav_menu" />
</android.support.v4.widget.DrawerLayout>
Hope you can help me.
Thanks!
You can create swipe views using AndroidX's ViewPager widget. To use ViewPager and tabs, you need to add a dependency on ViewPager and on Material Components to your project. To insert child views that represent each page, you need to hook this layout to a PagerAdapter .
Establish the link by creating an instance of this class, make sure the ViewPager2 has an adapter and then call attach() on it. Instantiating a TabLayoutMediator will only create the mediator object, attach() will link the TabLayout and the ViewPager2 together.
I added:
android:layoutDirection="ltr"
to TabLayout
.
NOT
android:layoutDirection="rtl"
and it worked just fine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With