티스토리 뷰

728x90

 

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:itemBackground="@color/white"
        app:itemIconTint="@animator/menu_selector_color"
        app:itemTextColor="@animator/menu_selector_color"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:labelVisibilityMode="labeled"
        app:menu="@menu/bottom_nav_menu" />

app:itemBackground - 이 속성을 통해 background color 지정시 메뉴 클릭 효과 나타나지 않음

app:itemIconTint - icon의 색상

app:itemTextColor - text의 색상

app:labelVisibilityMode - labeled로 지정시 icon과 함께 label이 항상 띄워짐 (아이콘만 띄우고 싶을 때 unlabeled)

 

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#9375E3" android:state_checked="true" />
    <item android:color="#2b2b2b" android:state_checked="false" />
</selector>

item이 클릭되었을 때, 클릭되지 않았을 때 color를 지정해주고 싶은 경우,

위와 같이 color xml 파일을 생성한다. (res/animator 폴더 안에)

state_checked="true"는 클릭되었을 때 color를 지정, false는 클릭되지 않았을 때 color를 지정.

 

그리고 app:itemIconTint와 app:itemTextColor의 속성을 이 xml 파일명으로 지정해주면 된다.

 

 

 

참고

https://jjuha-dev.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-Bottom-Navigation-View-%EC%83%89%EC%83%81-%EB%B3%80%EA%B2%BD%ED%95%98%EA%B8%B0

https://nuritech.tistory.com/13

 

728x90
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함