본문 바로가기
개발/Android

[Android] BottomNavigationView 선택되지 않은 메뉴의 라벨이 보이지 않을 때

by JhDroid 2021. 4. 3.
728x90

개요

  • BottomNavigationView 사용 시 선택된 메뉴만 라벨(텍스트)이 보이고 선택되지 않은 메뉴는 보이지 않을 때 설정 방법

선택된 메뉴만 라벨이 보인다.

 

설정 방법

  • BottomNavigationView 설정에 setLabelVisibilityMode의 설정을 변경해준다.
<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <androidx.constraintlayout.widget.ConstraintLayout
		...

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_nav_view"
            android:layout_width="0dp"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/purple_700"
            android:theme="@style/BottomNavTheme"
            app:labelVisibilityMode="labeled"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:menu="@menu/nav_menu" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>
  • xml에서는 app:labelVisibilityMode"labeled"로 설정
binding.bottomNavView.labelVisibilityMode = LabelVisibilityMode.LABEL_VISIBILITY_LABELED
  • 코드에서 설정해줄 때는 setLabelVisibilityModeLabelVisibilityMode.LABEL_VISIBILITY_LABELED 설정

설정 후 모든 메뉴의 라벨이 보이는 것을 확인 가능하다.

 

* 글에 틀린 부분이 있으면 댓글 부탁드립니다 :D

728x90