在android中按下时更改选项卡布局的选项卡中的文本大小

时间:2019-02-26 08:55:10

标签: android tabs

我想知道如何在TabLayout中选定的选项卡上将文本大小更改为更大。在其他android view组件中,可以使用选择器来实现,但是我在TabLayout上尝试过选择器,但它不起作用。我该如何实现? 谢谢您的关注。

2 个答案:

答案 0 :(得分:0)

            ********---BottomNavigation Style---********
<style name="AppTheme.BottomNavigation"parent="Widget.MaterialComponents.BottomNavigationView">
    <item name="android:background">@color/colorWhite</item>
    <item name="labelVisibilityMode">labeled</item>
    <item name="itemIconTint">@color/bottom_nav_icon_color_selector</item>
    <item name="itemTextColor">@color/bottom_nav_icon_color_selector</item>
    <item name="itemTextAppearanceActive">@style/TextAppearanceActive</item>
    <item name="itemTextAppearanceInactive">@style/TextAppearanceInactive</item>
</style>



            ********---Font Size Style---********
<style name="TextAppearanceActive" parent="android:TextAppearance">
    <item name="android:fontFamily">@font/font_sf_regular</item>
    <item name="fontFamily">@font/font_sf_regular</item>
    <item name="fontStyle">normal</item>
    <item name="android:textSize">@dimen/font10</item>
</style>


//InActive Style
 <style name="TextAppearanceInactive" parent="TextAppearanceActive">
        <item name="android:textSize">@dimen/font9</item>
</style>


<com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/navigation"
            style="@style/AppTheme.BottomNavigation"
            android:layout_width="match_parent"
            android:layout_height="@dimen/_50dp"
            android:layout_gravity="bottom"
            app:menu="@menu/navigation" />

答案 1 :(得分:0)

下面的最简单答案-

tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            TextView textView = (TextView) tab.getCustomView();
            if (textView != null) {
                textView.setTextColor(getResources().getColor(R.color.c_white));
                textView.setTextSize(24);
            }
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            TextView textView = (TextView) tab.getCustomView();
            if (textView != null) {
                textView.setTextColor(getResources().getColor(R.color.c_grey));
                textView.setTextSize(18);
            }
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });