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

问题描述 投票:1回答:2

我想知道如何在TabLayout中的选定选项卡上更大文本大小。在其他android视图组件中,它可以实现使用选择器,但我已经在TabLayout上尝试了选择器,它不起作用。我怎样才能做到这一点?谢谢你的关注。

android tabs
2个回答
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" />

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) {
        }
    });
© www.soinside.com 2019 - 2024. All rights reserved.