Нижняя панель навигации: размер текста увеличивается при нажатии?

Я использую нижнюю панель навигации в Android. По умолчанию, когда я выбираю элемент, размер текста метки этого элемента увеличивается. Как видно на этикетке «турниры».

введите описание изображения здесь

введите описание изображения здесь

Есть ли способ удалить это так, чтобы слово «турниры» осталось прежнего размера?


person Lewis Black    schedule 27.11.2017    source источник


Ответы (6)


Попробуйте добавить этот код в dimens.xml файл

<dimen name="design_bottom_navigation_text_size" tools:override="true">10sp</dimen>
<dimen name="design_bottom_navigation_active_text_size" tools:override="true">10sp</dimen>
person Mitesh Vanaliya    schedule 27.11.2017
comment
Я не получаю журнала ошибок. Я даже попытался изменить значение размера текста в файле value.xml библиотеки и установить badge_text_size на 50sp. Но все равно не повезло. - person viper; 02.08.2018
comment
Спасибо за решение, оно сэкономило мне много времени! - person hetsgandhi; 30.03.2020

Вы можете установить активный и неактивный textAppearance для BottomNavigationView с помощью стилей:

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/BottomNavigationView"/>

Поместите ниже стили в styles.xml файл

<style name="BottomNavigationView">
    <item name="itemTextAppearanceActive">@style/TextAppearance.BottomNavigationView.Active</item>
    <item name="itemTextAppearanceInactive">@style/TextAppearance.BottomNavigationView.Inactive</item>
</style>

 <!-- blank styles for better code readability-->
<style name="TextAppearance"/>
<style name="TextAppearance.BottomNavigationView"/>

<!-- inactive tab icon style -->
<style name="TextAppearance.BottomNavigationView.Inactive">
    <item name="android:textSize">12sp</item>
</style>

<!-- active tab icon style -->
<style name="TextAppearance.BottomNavigationView.Active">
    <item name="android:textSize">12sp</item>
</style>

С TextAppearance вы можете управлять не только textSize, но и такими свойствами, как fontFamily и т. Д.

person Jason Grife    schedule 13.09.2018
comment
Работает для меня. Большое спасибо - person nimelorm; 28.11.2018
comment
Ссылка на используемые атрибуты: github.com/material-components/material-components-android/blob/. - person nimelorm; 28.11.2018

Если вы используете библиотеку поддержки '28.0.0-alpha1' или выше, вам нужно сделать 2 простые вещи:

Добавьте две строки ниже в файл dimen.xml

<dimen name="design_bottom_navigation_text_size" tools:override="true">15sp</dimen>
<dimen name="design_bottom_navigation_active_text_size" tools:override="true">15sp</dimen>

А ввиду -

<android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            android:foreground="?attr/selectableItemBackground"
            app:itemIconTint="@color/colorAccent"
            app:itemTextColor="@color/colorAccent"
            android:elevation="16dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:labelVisibilityMode="labeled"
            app:menu="@menu/navigation" />

Положите app:labelVisibilityMode="labeled"

Вот и все нравится :-)

person Bajrang Hudda    schedule 26.12.2018

Все элементы управления пользовательского интерфейса BottomNavigationView ниже. Я использовал зависимость com.google.android.material: material для BottomNavigationView.

 private void editBottomNavigationViewItems(BottomNavigationView bottomNavigationView) {

        for (int i = 0; i < bottomNavigationView.getChildCount(); i++) {

            try {

                View item = bottomNavigationView.getChildAt( i );

                if (item instanceof BottomNavigationMenuView) {

                    BottomNavigationMenuView menu = (BottomNavigationMenuView) item;
                    for (int j = 0; j < menu.getChildCount(); j++) {

                        try {

                            View menuItem = menu.getChildAt( j );

                            // not chosen item menu  GO
                            View _small = menuItem.findViewById(com.google.android.material.R.id.smallLabel);//dependence com.google.android.material:material
                            //View _small = menuItem.findViewById(android.support.design.R.id.smallLabel);// dependence android.support.design
                            if ( _small instanceof TextView ) {
                                //_small.setPadding(0, 0, 0, 0);// remove all padding
                                TextView _tv = (TextView)_small;
                                _tv.setTextSize( 12 );// set size text
                            }// not chosen item menu  END

                            //this chosen item menu GO
                            View _large = menuItem.findViewById(com.google.android.material.R.id.largeLabel);//dependence com.google.android.material:material
                            //View _large = menuItem.findViewById(android.support.design.R.id.largeLabel);//dependence android.support.design.R.id.largeLabel
                            if ( _large instanceof TextView ) {
                                _large.setPadding(0,0,0,0);// remove all padding
                                TextView _tv = (TextView)_large;
                                _tv.setTextSize( 12 );// set size text
                            }// this chosen item menu  END

                        } catch ( NullPointerException npei ) {
                            Log.e("TAG", "get:BottomNavigationMenuView: " + npei.getMessage() );
                        }

                    }

                }

            } catch ( NullPointerException npe ) {
                Log.e("TAG", "get:BottomNavigationView: " + npe.getMessage() );
            }

        }

    }
person amiron    schedule 06.09.2019
comment
это было решением для меня, перебирать каждую большую метку и удалять отступы. Спасибо! - person Pedro Antonio; 16.06.2020

Используйте этот метод в onCreate () и перед bottom_navigation_menu.setOnNavigationItemSelectedListener: -

public void removePaddingFromBottomNavigationItem() {
        BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottom_navigation_menu.getChildAt(0);
        for (int i = 0; i < menuView.getChildCount(); i++) {
            BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
            View activeLabel = item.findViewById(R.id.largeLabel);
            if (activeLabel instanceof TextView) {
                activeLabel.setPadding(0, 0, 0, 0);
            }
        }
    }

И используйте этот код в styles.xml: -

<style name="TextAppearance.BottomNavigationView.Inactive">
    <item name="android:textSize">@dimen/_10ssp</item>
</style>

<style name="TextAppearance.BottomNavigationView.Active">
    <item name="android:textSize">@dimen/_10ssp</item>
</style>
person Ankit Lathiya    schedule 07.12.2019

Попробуйте со строкой ниже в dimen.xml

<dimen name="design_bottom_navigation_text_size" tools:override="true">8sp</dimen>
<dimen name="design_bottom_navigation_active_text_size" tools:override="true">8sp</dimen>
<dimen name="design_bottom_navigation_icon_size">15dp</dimen>
<dimen name="design_bottom_navigation_height">45dp</dimen>
person Mahmoud D. Alghraibeh    schedule 01.07.2020