마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

이 속성이 뭔지 모르겠습니다

0 추천

img

 

navigationview에서 선택된 아이템의 텍스트가 하얀색이라 별로 보기 좋지 않아서 바꾸려고 하는데 이 속성이 뭔지를 모르겠습니다.

ㅇㅇㅇㅇㅇㅇㅇㅇ (1,000 포인트) 님이 2022년 2월 13일 질문

1개의 답변

+1 추천
 
채택된 답변

 material design이 복잡해서 문서를 참고하시면 좋을 것 같네요.

https://material.io/components/navigation-drawer/android#anatomy

위 페이지에서 

4. Active text overlay
5. Active text

 원하시는 부분인 것 같네요.

Text Atribute 섹션을 보면

Colorapp:itemTextColorsetItemTextColor
getItemTextColor
?attr/colorPrimary when active else ?attr/colorOnSurface (see all states)

 

app:itemTextolor 속성을 지정하라고 되어 있네요. 아이템 선택시 기본값으로는 colorPrimary의 색깔을 사용한다고 되어 있습니다. 현재 colourOnSurface가 흰색으로 되어 있으신 듯 하네요. 이걸 변경하시던가, 따라서 아래처럼 NavigationDrawer의 스타일을 하나 정의하고 이걸 가져다 사용하시면 되지 않을까 생각합니다.

theme.xml

<style name="DrawerTheme" parent="Widget.MaterialComponents.Toolbar.PrimarySurface">
        <item name="android:background">@color/white</item>
        <item name="colorOnPrimary">@color/wanted_color</item>
</style>

 

<com.google.android.material.navigation.NavigationView
        style="@style/DrawerTheme" <!-- 여기에 정의된 style 사용 -->
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

 

spark (227,510 포인트) 님이 2022년 2월 14일 답변
ㅇㅇㅇㅇㅇㅇㅇㅇ님이 2022년 2월 14일 채택됨
감사합니다... 지금 다크모드 적응성도 배우기 위해 테마를 공부하고 있는데
명확한 커리큘럼을 찾기 힘들어서 꼴아박으며 배우느라 미숙한 부분이 많네요..

colorOnSurface 속성은 있는줄도 몰라서 아마 Primary인 하얀색으로 적용된거같습니다
정말 감사합니다
...