Tuesday, 3 September 2019

Duolingo's RTL ViewPager Overrides TabLayout font

I'm setting the TabLayout's tabs into a custom font using the below code:

Locale locale = Locale.getDefault();
if (locale.equals(new Locale("ar"))) {
    for (int i = 0; i < tabs.getTabCount(); i++) {
        @SuppressLint("InflateParams") TextView tv = (TextView)LayoutInflater.from(this).inflate(R.layout.custom_tabview,null);
        tv.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/JannaLT-Regular.ttf"));
        Objects.requireNonNull(tabs.getTabAt(i)).setCustomView(tv);
    }
}

This works fine until I replace my ViewPager in XML with the RtlViewPager library, because Google, for some reason, still hasn't fixed the awkwardly incorrect swiping in RTL layouts.

<com.duolingo.open.rtlviewpager.RtlViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

Before:

<androidx.viewpager.widget.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

The font doesn't want to change. By debugging I can tell that the if statement is still being executed, and so is the for-loop along with everything inside it. But it just doesn't change. Simply changing it from ViewPager to RtlViewPager, for some reason, causes the TabLayout to refuse any layout changes. Even trying to set the text color to red doesn't work.



from Duolingo's RTL ViewPager Overrides TabLayout font

No comments:

Post a Comment