Ich verwende Calligraphy Bibliothek, um benutzerdefinierte Schriftart anwenden. Ich habe ein Problem mit TabLayout
, wo die Schriftart nicht gilt. Also muss ich es manuell mit dem Follow-Code festgelegt:Ändern Sie die ausgewählte Registerkarte Farbe für Tablayout mit benutzerdefinierten Schriftart
mViewPager.setAdapter(pagerAdapter);
tabLayout.setupWithViewPager(mViewPager);
for (int i = 0; i < pagerAdapter.getCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
if (tab != null) {
tab.setCustomView(R.layout.tab_text);
tab.setText(pagerAdapter.getPageTitle(i));
}
}
Die XML-Datei auf die benutzerdefinierte Registerkarte Ansicht
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:textSize="@dimen/item_txt_size"
android:textColor="@color/progress_color"
android:maxLines="2"
app:fontPath="fonts/font_regular.ttf"
tools:ignore="MissingPrefix"
tools:text="User Profile" />
</FrameLayout>
Die XML der Ansicht:
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_below="@id/map_google"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@color/progress_color"
app:tabIndicatorHeight="@dimen/indicator_height"
android:background="@color/actionbar_home"
app:tabMode="fixed"
app:tabTextColor="@android:color/white"
app:tabSelectedTextColor="@color/progress_color"
app:tabGravity="fill"/>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_below="@id/tabs"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
Das Problem ist die ausgewählte Farbe und die nicht ausgewählten gelten nicht, es ist immer die gleiche Farbe.
Vielen Dank, Sie haben mich gerettet –